-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Ensure null
with Maybe
#571
Comments
Yeah, sounds useful enough. Feel free to submit a PR. Can't think of a better name than |
Hey @DerStimmler, @vkhorikov, |
If I'm correct with my thinking, this will return a vanilla But I believe it would probably make sense to add overrides which could do just that, like: See #588, any thoughts? |
Hi @bothzoli, I think you are right with I don't think we need the compensate func since there is already a Maybe.From("Foo")
.ToInvertedResult("Bar")
.Compensate(error => ...) Since we can create await Maybe.From(Task.FromResult("Foo"))
.ToInvertedResult("Bar"); Here are some async examples for the normal |
Hey @DerStimmler, |
@DerStimmler I've finalised the PR, feel free to review. |
Great, I'll have a look at it. |
Currently, the
ToResult
method onMaybe
returns a success result if theMaybe
has a value, and a failure result if there is no value.But what if it should be the other way around?
Lets say I want to create a report, but only if no report already exists.
Right now I would probably do something like this:
But this comes with some overhead because I have to start the chain with an empty success result to then map the nullable value and ensure its
null
using theEnsure
method.I think it would be more appropriate and compact to use
Maybe
and itsToResult
method since I'm dealing with a nullable.But to keep the chain running if the
Maybe
has no value, I basically need an invertedToResult
method that returns a success result if there is no value. E.g:What do you think about this addition?
ToInvertedResult
is just an example name because I can't think of anything better. 😄The text was updated successfully, but these errors were encountered: