Skip to content
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

Merged
merged 6 commits into from
Jan 6, 2025

Conversation

PI-Gorbo
Copy link
Contributor

@PI-Gorbo PI-Gorbo commented Dec 22, 2024

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 it require to be more in line with the other requireX 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

Copy link
Collaborator

@TheAngryByrd TheAngryByrd left a 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.

SamLaptop added 2 commits January 1, 2025 14:46
@PI-Gorbo
Copy link
Contributor Author

PI-Gorbo commented Jan 1, 2025

Happy new year! Same with the holidays getting in my way.
I've sent a fix - I had a duplicated test. Sorry about that 🤦

Copy link
Collaborator

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@TheAngryByrd TheAngryByrd merged commit aabde8d into demystifyfp:master Jan 6, 2025
27 checks passed
TheAngryByrd added a commit that referenced this pull request Jan 6, 2025
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants