question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deprecate OnFailure()

See original GitHub issue

Similar to the recent refactoring in #141, I propose to:

  1. Refactor OnFailure into MapFailure and mark OnFailure as [Obsolete]. This will bring extension methods to consistency with F#'s Result at https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/result.fs (MapFailure and not MapError because Error and IsFailure are different members in our Result and Failure is closer semantically to describing the result’s state).

  2. Move the existing MapFailure methods out of Result/Result<T>/Result<T,E> to extensions that replace OnFailure ( https://github.com/vkhorikov/CSharpFunctionalExtensions/blob/master/CSharpFunctionalExtensions/Result/Result.cs#L554-L567 and similar).

@space-alien let me know if you can do that. If you are short on time, I’ll try to refactor myself this weekend.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
space-aliencommented, Sep 16, 2019

Have pushed a commit renaming MapFailure -> ConvertFailure. Work continues on the other points.

1reaction
space-aliencommented, Sep 8, 2019

I remembered your comment on #135. I had also been thinking along these lines for a while.

One option would be to refactor as follows:

Map(Func<K> onSuccess, Func<K> onFailure)
MapSuccess(Func<K> func) // i.e. the current Map behaviour (if starting with a failure, return a failure result of the new type)
MapFailure(Func<K> func) // Opposite of MapSuccess

And the same principle for Bind() and Tap():

Bind(Func<Result> onSuccess, Func<Result> onFailure)
BindSuccess(Func<Result> func)
BindFailure(Func<Result> func)

Tap(Action onSuccess, Action onFailure)
TapSuccess(Action action)
TapFailure(Action action)

Fortunately, I don’t think any of this would be a breaking change (even with the current MapFailure).

I’m still trying to decide if I have an issue with the semantics of MapFailure / MapSuccess, and their Bind/Tap equivalents. For the reader unfamiliar with the library, it may not be instantly obvious whether:

  1. The func is mapped/tapped/bound IF the starting result is in the named success/failure state, or
  2. The func is ALWAYS called and the returned result will be changed into the named success/failure state.

It may be pretty daft to infer (2), but any ambiguity potentially draws some of the reader’s brainpower to reach the right conclusion. And one of the benefits of this library has always been its ability to make expected behaviour obvious.

So, here’s the “blindingly-obvious” alternative…!

Map()
Tap()
Bind()

OnSuccessMap()
OnSuccessTap()
OnSuccessBind()

OnFailureMap()
OnFailureBind()
OnFailureTap()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Deprecate OnFailure in favour of OnAnyFailure · Issue #1590
OnFailure should be deprecated in 10.x and removed in 1010. Users should migrate to OnAnyFailure instead. Users may need assistance migrating if ...
Read more >
11.0 Upgrade Guide — FluentValidation documentation
The deprecated methods OnFailure and OnAnyFailure have been removed. These were callbacks that could be used to define an action that would be...
Read more >
Refactor a ListenableFuture (with onSuccess/onFailure) ...
But the ListenableFuture.onFailure doesn't have a clear equivalent. There is CompletableFuture.exceptionally which must return something, which ...
Read more >
HTMLImageElement onerror Event Handler is Deprecated
Shot from MDM showing the deprecated trashcan icon next to onerror. I've always just plonked a onerror() handler on my image elements when...
Read more >
ListenableFutureCallback (Spring Framework 6.0.11 API)
@Deprecated(since="6.0") public interface ListenableFutureCallback<T> extends SuccessCallback<T>, FailureCallback. Deprecated. ... onFailure ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found