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

Expand FailIf #189

Open
virzak opened this issue Jun 23, 2023 · 0 comments
Open

Expand FailIf #189

virzak opened this issue Jun 23, 2023 · 0 comments

Comments

@virzak
Copy link

virzak commented Jun 23, 2023

I am using the following to fill functionality that's missing for my project. What are your thoughts on this and will you take a PR with similar functionality?

static class MyResult
{
    public static Result FailIf(bool isFailure, IEnumerable<IError> errors)
        => isFailure ? Result.Fail(errors) : Result.Ok();
    
    public static Result FailIfNotEmpty(IEnumerable<IError> errors)
        => errors.Any() ? Result.Fail(errors) : Result.Ok();

    public static Result FailIfNotEmpty<T>(IEnumerable<T> errors, Func<T, IError> func)
        => errors.Any() ? Result.Fail(errors.Select(error => func(error))) : Result.Ok();
}
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

No branches or pull requests

1 participant