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 OrFailIf extension method #221

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martin-hirsch
Copy link

Hello there,

This pull request introduces a new extension method, OrFailIf, to the Result class.

I hope you don't mind that I went ahead and created this pull request directly. I felt a separate discussion wasn't necessary since this addition is minor, straightforward, and self-explanatory.

I often find myself needing to split Result.Merge() statements to provide more detailed error messages, particularly for null checks. To avoid repetitive code in every validation, I believe this feature offers a clean and effective solution to that problem.

Looking forward to your feedback!

Best regards,
Martin

With this extension method it is easier to chain several FailIf statements together.
@Kilazur
Copy link

Kilazur commented Oct 4, 2024

We made multiple extension methods at my job to deal with failures. I can't legally share it, but you may want to add methods that take a predicate as a parameter, that acts on the value of a Result, so you can fail if the value isn't valid contextually.

You can also add other signature of this method to follow the existing formats of methods acting on Result and Task, like Bind.

@martin-hirsch
Copy link
Author

That's exactly what I always found myself doing. Creating or copying the same extension methods from over and over again.

This time I'll try to contribute. 🚀

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