DrifterApps.Seeds.FluentResult
1.1.20
dotnet add package DrifterApps.Seeds.FluentResult --version 1.1.20
NuGet\Install-Package DrifterApps.Seeds.FluentResult -Version 1.1.20
<PackageReference Include="DrifterApps.Seeds.FluentResult" Version="1.1.20" />
<PackageVersion Include="DrifterApps.Seeds.FluentResult" Version="1.1.20" />
<PackageReference Include="DrifterApps.Seeds.FluentResult" />
paket add DrifterApps.Seeds.FluentResult --version 1.1.20
#r "nuget: DrifterApps.Seeds.FluentResult, 1.1.20"
#:package DrifterApps.Seeds.FluentResult@1.1.20
#addin nuget:?package=DrifterApps.Seeds.FluentResult&version=1.1.20
#tool nuget:?package=DrifterApps.Seeds.FluentResult&version=1.1.20
<img alt='paper plane icons' src='./icon.png' height='10%' width='10%'> FluentResult
FluentResult is a C# library that provides a fluent API for handling results of operations, including success and failure cases. It includes various utilities and extensions to simplify error handling and result aggregation.
Some of my inspirations comes from Andrew Lock's Series: Working with the result pattern
Table of Contents
Installation
To install FluentResult, you can use the NuGet package manager:
dotnet add package DrifterApps.Seeds.FluentResult
Usage
Basic Result Handling
You can create and handle results using the Result class and its extension methods.
using DrifterApps.Seeds.FluentResult;
// Creating a success result by implicit conversion
Result<int> successResult = 42;
// Creating a success result by ToResult extension method
var successResult = 45.ToResult<int>();
// Creating a failure result by implicit conversion
Result<int> failureResult = new ResultError("Error.Code", "Error description");
// Creating a failure result by ToResult extension method
failureResult = new ResultError("Error.Code", "Error description").ToResult<int>();
// Handling success and failure
var finalResult = successResult.OnSuccess(value => (Result<string>)value.ToString())
.OnFailure(error => (Result<string>)error);
Aggregating Results
You can aggregate multiple results using the ResultAggregate class.
using DrifterApps.Seeds.FluentResult;
var resultAggregate = ResultAggregate.Create();
Result<Nothing> successResult = Nothing.Value;
Result<Nothing> failureResult = new ResultError("Error.Code", "Error description");
resultAggregate.AddResult(successResult);
resultAggregate.AddResult(failureResult);
bool isSuccess = resultAggregate.IsSuccess; // false
bool isFailure = resultAggregate.IsFailure; // true
Asynchronous Result Handling
You can handle results asynchronously using the extension methods provided in ResultExtensions.Async.
using DrifterApps.Seeds.FluentResult;
var resultTask = Task.FromResult((Result<int>)42);
var finalResult = await resultTask.OnSuccess(async value => await Task.FromResult((Result<string>)value.ToString()))
.OnFailure(async error => await Task.FromResult((Result<string>)error));
Matching Results
You can perform different actions based on success or failure:
using DrifterApps.Seeds.FluentResult;
Result<int> result = 42;
result.Match(
onSuccess: value => Console.WriteLine($"Success with value: {value}"),
onFailure: error => Console.WriteLine($"Error: {error.Code} - {error.Message}")
);
Ensuring Validation
You can ensure that a specific validation function returns true using the Ensure method. If the validation fails, it
adds a failure result to the source.
using DrifterApps.Seeds.FluentResult;
var aggregate = ResultAggregate.Create();
aggregate.AddResult(new ResultError("Error.Code", "Initial error"));
// Ensure validation with IgnoreOnFailure option
var result = aggregate.Ensure(() => true, new ResultError("Validation.Error", "Validation failed"), EnsureOnFailure.IgnoreOnFailure);
// Ensure validation with default ValidateOnFailure option
var resultWithValidation = aggregate.Ensure(() => false, new ResultError("Validation.Error", "Validation failed"));
bool isSuccess = result.IsSuccess; // true
bool isFailure = result.IsFailure; // false
bool isValidationSuccess = resultWithValidation.IsSuccess; // false
bool isValidationFailure = resultWithValidation.IsFailure; // true
AI Coding Assistants
This repository ships instruction files for the most common AI coding assistants. If you are using this library in your own project, copy the file for your IDE into your repository so your AI assistant understands the Result pattern and generates correct code without prompting.
| IDE / Tool | Instruction file | Where to copy it in your project |
|---|---|---|
| Claude Code | CLAUDE.md | CLAUDE.md at the project root |
| GitHub Copilot | copilot-instructions.md | .github/copilot-instructions.md |
| Cursor | fluentresult.mdc | .cursor/rules/fluentresult.mdc |
| Windsurf | fluentresult.md | .windsurf/rules/fluentresult.md |
| JetBrains AI (Junie) | guidelines.md | .junie/guidelines.md |
Tip: you only need the file for the IDE you are using.
Quick copy via curl
# Claude Code
curl -sLo CLAUDE.md https://raw.githubusercontent.com/patmoreau/drifterapps-seeds-fluentresult/main/CLAUDE.md
# GitHub Copilot
mkdir -p .github && curl -sLo .github/copilot-instructions.md https://raw.githubusercontent.com/patmoreau/drifterapps-seeds-fluentresult/main/.github/copilot-instructions.md
# Cursor
mkdir -p .cursor/rules && curl -sLo .cursor/rules/fluentresult.mdc https://raw.githubusercontent.com/patmoreau/drifterapps-seeds-fluentresult/main/.cursor/rules/fluentresult.mdc
# Windsurf
mkdir -p .windsurf/rules && curl -sLo .windsurf/rules/fluentresult.md https://raw.githubusercontent.com/patmoreau/drifterapps-seeds-fluentresult/main/.windsurf/rules/fluentresult.md
# JetBrains AI (Junie)
mkdir -p .junie && curl -sLo .junie/guidelines.md https://raw.githubusercontent.com/patmoreau/drifterapps-seeds-fluentresult/main/.junie/guidelines.md
Contributing
Contributions are welcome! Please read the contributing guidelines for more information.
License
This project is licensed under the MIT License. See the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on DrifterApps.Seeds.FluentResult:
| Package | Downloads |
|---|---|
|
DrifterApps.Seeds.Application
Package Description |
|
|
DrifterApps.Seeds.Application.Mediatr
Package Description |
|
|
DrifterApps.Seeds.FluentResult.FluentAssertions
Package Description |
|
|
FluentResult.FluentAssertions
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.20 | 177 | 5/14/2026 |
| 1.1.19 | 41 | 5/14/2026 |
| 1.1.18 | 42 | 5/13/2026 |
| 1.1.15 | 1,156 | 1/25/2026 |
| 1.1.14 | 604 | 12/26/2025 |
| 1.1.10 | 661 | 11/25/2025 |
| 1.1.6 | 942 | 6/24/2025 |
| 1.1.5 | 1,410 | 6/1/2025 |
| 1.1.4 | 226 | 6/1/2025 |
| 1.1.0 | 2,254 | 3/15/2025 |
| 1.0.2 | 244 | 3/11/2025 |
| 1.0.0 | 250 | 3/11/2025 |
| 0.1.21 | 2,256 | 1/17/2025 |
| 0.1.19 | 303 | 1/16/2025 |
| 0.1.12 | 670 | 12/3/2024 |
| 0.1.10 | 785 | 11/28/2024 |
| 0.1.8 | 1,298 | 11/13/2024 |
| 0.1.7 | 1,644 | 10/22/2024 |
| 0.1.6 | 490 | 10/21/2024 |
| 0.1.5 | 203 | 10/21/2024 |