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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

PI-Gorbo
Copy link

@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 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
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 🤦

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