-
Notifications
You must be signed in to change notification settings - Fork 140
Added convenience methods for easier Monad creation and Monad chaining #258
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
base: develop
Are you sure you want to change the base?
Conversation
@dotnet-policy-service agree |
@julianthurner , thanks for your contribution! According to the Contribution Guideline, could you change the target branch from |
Changing the target branch is not enough. Also, after the discussion of the API, units tests need to be added as well. |
e1ee1f1
to
f58043f
Compare
I would suggest to review the proposed API again from your side, since 5.19.0 has been released:
|
Looks nice👍I will review the changes and adjust them accordingly, sometime this week probably. |
Well, life got in the way ... |
@sakno Sorry it took me this long. My exams were eating up any brain capacity I had, but luckily they are over now. Please take a look at the updated version. I will add Unit Tests once the API is finished. |
@sakno If you approve of the current state, I will implement Unit Tests next. |
/// <typeparam name="T">The type of the value.</typeparam> | ||
/// <typeparam name="TResult">The type of the result of the mapping function.</typeparam> | ||
/// <returns>The conversion result.</returns> | ||
public static AwaitableResult<TResult> Convert<T, TResult>(this AwaitableResult<T> task, Converter<T, TResult> converter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AwaitableResult
is a leaf type. It cannot be used to build a chain, as discussed above. Please review the rest of the methods where the type is used as an input parameter.
I added some convenience methods to the library. The Option class receives a few extension methods that allow for chaining async conversions:
This is really useful if you work with databases where data is fetched / transformed multiple times asynchronously before being filled into a DTO.
The same thing for Result:
This also forwards the exception up the chain just like with regular monads.
There's also overloads for converting Option ↔ Result in both directions if there's need for conversion within a chain.
Also, I added some additional convenience methods for creating Options and Results statically: