-
Notifications
You must be signed in to change notification settings - Fork 142
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 ... |
fae3f59
to
b645fe8
Compare
@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. |
2766492
to
c950a28
Compare
@sakno Are you content with the current state of the API? |
@sakno While implementing Unit Tests, I noticed that trying to access the unsafe versions of both the existing ConvertOptional() and newly added ConvertResult() methods results in an error due to ambiguity (see attached screenshots). If this is not surpassable by some means, I think that the unsafe versions of both methods should be removed. ![]() ![]() |
@sakno Also, the Linux Tests seem to fail due to timeout. What can I do about that? |
Try to specify generic argument explicitly to help the compiler.
Yeah, it's a flaky issue caused by synchronization context used by xUnit infrastructure. You can just restart the test from Azure DevOps. From time to time I'm improving the stability of the tests, but it's not completely fixed. |
171c94e
to
c77f6a6
Compare
@sakno Thanks, I got the unsafe versions to work and after a few restarts, the Linux Tests managed to finish without timeout. |
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: