Skip to content

It is a library that extends the popular FluentResults library and helps you write code in a more functional way.

License

Notifications You must be signed in to change notification settings

nkz-soft/NKZSoft.FluentResults.Extensions.Functional

Repository files navigation

NKZSoft.FluentResults.Functional.Extensions

GitHub release (latest SemVer) license GitHub Workflow Status (with branch)

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#.

⭐ Give a star

If you're using this repository for your learning, samples or your project, please give a star. Thanks 👍

Installation

Available on NuGet

dotnet add package NKZSoft.FluentResults.Extensions.Functional

Features

All methods have asynchronous overloads and ValueTask support.

Bind

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);

Finally

Executes a function after a Result, regardless of its success or failure.

public async Task<int> OnBothAsync(Result result)
...
await Result.Ok().FinallyAsync(OnBothAsync);

Tap

Executes an action if the result is successful and return the original result.

public async Task OnActionAsync()
...
await Result.Ok().TapAsync(OnActionAsync);

Match

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);

Ensure

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);

About

It is a library that extends the popular FluentResults library and helps you write code in a more functional way.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages