Replies: 1 comment
-
Looks useful to me. Feel free to submit a PR. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I recently started using this library, and wrote some extension methods.
In particular, I found myself making Maybe<Result> and Maybe<Result>, so made some extension methods to make those easier to work with.
Do you think any of the ideas here would be useful in this library?
When you start with a field which might be null (eg user input), and then call
.Map
to try to parse it - you end up with aMaybe
ofResult
.But that's a pain to work with, because you have to dig into it to get any validation errors.
So I made an
.Optional()
extension method, which converts it to aResult
ofMaybe
and a
.Required()
extension, because the existing ToResult() would leave you with a Result of Result.Optional
Required is quite a bit simpler. I found creation was best left returning optional, and then if we want it to be required, that can be declared after words. So Required ends up working with a Result of Maybe, allowing us to do a simple bind.
I also added a special case for Map. to map an optional value (
Maybe
) to an optional result (Result
ofMaybe
).I think
EnsureNot
is also useful, and aBindOptional
to make it easier to mapResult
ofMaybe
ofT
- it allows you to write a mapping function which transformsT
, and not have to worry about the other wrappers.Beta Was this translation helpful? Give feedback.
All reactions