It is a library that extends the popular FluentResults library and helps you write code in a more functional way. The project was inspired by Functional Extensions for C#.
If you're using this repository for your learning, samples or your project, please give a star. Thanks 👍
Available on NuGet
dotnet add package NKZSoft.FluentResults.Extensions.Functional
All methods have asynchronous overloads and ValueTask support.
It executes the function only if the Result is successful (i.e., not failed). If the Result is failed, it returns the original failed Result. If the Result is successful, it executes the function and returns the resulting Result.
public async Task<Result<int>> OnSuccessAsync(int x)
...
await Result.Ok(1).BindAsync(OnSuccessAsync);
Executes a function after a Result, regardless of its success or failure.
public async Task<int> OnBothAsync(Result result)
...
await Result.Ok().FinallyAsync(OnBothAsync);
Executes an action if the result is successful and return the original result.
public async Task OnActionAsync()
...
await Result.Ok().TapAsync(OnActionAsync);
Matches a Result to either a success or failure action.
public async Task OnSuccessAsync()
...
public async Task OnFailureAsync(IList<IError> errors)
...
await Result.Ok().MatchAsync(OnActionAsync, OnFailureAsync);
Ensures that a condition is met for a successful Result. If the condition is not met, returns a failed Result with the specified error message.
var outputResult = await result.EnsureAsync(() => true, FailErrorMessage);