-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: Add Require and Check helper methods #295
feat: Add Require and Check helper methods #295
Conversation
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.
Thanks for this! Sorry holidays have made reviewing hectic.
Ran the CI and got:
[Expecto 00:00:18.7573892] FsToolkit.ErrorHandling.Tests: Found duplicated test names, these names are: [["All Tests.Result Tests.check tests.Using the result value in the predicate"]]
You'll have to disambiguate one of the tests.
…ErrorHandling-RequireAndCheck into feat/RequireAndCheck
Happy new year! Same with the holidays getting in my way. |
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.
Thank you!
- BREAKING: [Remove Ply and update to FSharp 6](#248) Credits @TheAngryByrd - BREAKING: [Remove MergeSources (and!) from some implementations like Result](#261) Credits @TheAngryByrd - BREAKING: [Merge TaskResult into Core library](#285) Credits @TheAngryByrd - This means FsToolkit.ErrorHandling.TaskResult is no longer a separate package and will not be updated. It is now part of the core library. - BREAKING: [Rename retn to singleton](#287) Credits @1eyewonder - [Use Microsoft.Bcl.AsyncInterfaces in netstandard2.0 (Allows IAsyncDisposable and IAsyncEnumerable)](#250) Credits @TheAngryByrd - [Build against Net8](#251) Credits @TheAngryByrd - [Fix Overload Resolution to Align to Computation Expression used](#252) Credits @TheAngryByrd - [refactor!: Seq.sequenceResultM returns Array instead of seq](#255) Credits @bartelink - [feat(Seq): sequenceResultA](#255) Credits @bartelink - [Updated uses of Seq.append](#290) Credits @1eyewonder - [Add Option.traverseAsync and Option.sequenceAsync](#298 (comment)) Credits @tw0po1nt - [Add Require and Check helper methods](#295) Credits @PI-Gorbo
Context
Starting from this Task #281, I have implemented two new methods for Result, TaskResult and AsyncResult.
Method 1 - Require
In the Issue i called it
ensure
, because that is what the C#FunctionalExtensions calls it, however I decided to name itrequire
to be more in line with the otherrequireX
functions.Require applies a predicate to the Ok value of a Result. If the predicate is false, then a new Error Result is returned with a user provided error.
Method 2 - Check
Same as described in the github task, check applies a more general function of the from
'ok -> Result<unit, 'error>
to the Ok value of a Result. It returns the original Ok value is the function returns Ok (), otherwise it returns the new error returned by the applied function.I have added docs.
I am super open to feedback and changes! Please fire away