https://github.com/nkz-soft/nkzsoft.fluentresults.extensions.functional
It is a library that extends the popular FluentResults library and helps you write code in a more functional way.
https://github.com/nkz-soft/nkzsoft.fluentresults.extensions.functional
csharp dotnet fluentresults functional-programming result result-pattern
Last synced: 8 months ago
JSON representation
It is a library that extends the popular FluentResults library and helps you write code in a more functional way.
- Host: GitHub
- URL: https://github.com/nkz-soft/nkzsoft.fluentresults.extensions.functional
- Owner: nkz-soft
- License: mit
- Created: 2024-08-28T14:43:20.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-06T13:04:48.000Z (9 months ago)
- Last Synced: 2025-01-11T14:45:29.775Z (9 months ago)
- Topics: csharp, dotnet, fluentresults, functional-programming, result, result-pattern
- Language: C#
- Homepage:
- Size: 68.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NKZSoft.FluentResults.Functional.Extensions


It is a library that extends the popular [FluentResults](https://github.com/altmann/FluentResults) library and helps you write code in a more functional way.
The project was inspired by [Functional Extensions for C#](https://github.com/vkhorikov/CSharpFunctionalExtensions).### ⭐ Give a star
If you're using this repository for your learning, samples or your project, please give a star. Thanks :+1:
## Installation
Available on [NuGet](https://www.nuget.org/packages/NKZSoft.FluentResults.Extensions.Functional/)
```bash
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.```csharp
public async Task> OnSuccessAsync(int x)
...
await Result.Ok(1).BindAsync(OnSuccessAsync);
```### Finally
Executes a function after a Result, regardless of its success or failure.
```csharp
public async Task OnBothAsync(Result result)
...
await Result.Ok().FinallyAsync(OnBothAsync);
```
### TapExecutes an action if the result is successful and return the original result.
```csharp
public async Task OnActionAsync()
...
await Result.Ok().TapAsync(OnActionAsync);
```### Match
Matches a Result to either a success or failure action.
```csharp
public async Task OnSuccessAsync()
...
public async Task OnFailureAsync(IList 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.```csharp
var outputResult = await result.EnsureAsync(() => true, FailErrorMessage);
```