Nautilus.FluentResult
0.0.3
See the version list below for details.
dotnet add package Nautilus.FluentResult --version 0.0.3
NuGet\Install-Package Nautilus.FluentResult -Version 0.0.3
<PackageReference Include="Nautilus.FluentResult" Version="0.0.3" />
<PackageVersion Include="Nautilus.FluentResult" Version="0.0.3" />
<PackageReference Include="Nautilus.FluentResult" />
paket add Nautilus.FluentResult --version 0.0.3
#r "nuget: Nautilus.FluentResult, 0.0.3"
#:package Nautilus.FluentResult@0.0.3
#addin nuget:?package=Nautilus.FluentResult&version=0.0.3
#tool nuget:?package=Nautilus.FluentResult&version=0.0.3
Nautilus.FluentResult
A type-safe, fluent Result Pattern implementation for .NET applications. This library provides structured error handling that avoids exceptions for expected failures, making your code more predictable and easier to test.
Features
- Type-Safe: Strongly-typed success/failure handling
- Structured Errors: Errors contain both code and description
- Implicit Conversions: Easy conversion between values and results
- Null Safety: Proper null handling for values and errors
- .NET 9.0: Built on the latest .NET platform
- Zero Dependencies: No external dependencies
Installation
Install the package via NuGet:
dotnet add package Nautilus.FluentResult
Or via the Package Manager Console:
Install-Package Nautilus.FluentResult
Quick Start
Basic Usage
using Nautilus.FluentResult;
// Create a success result
Result result = Result.Success();
if (result.IsSuccess)
{
Console.WriteLine("Operation succeeded!");
}
// Create a failure result
Error error = new Error("VALIDATION_ERROR", "Invalid input");
Result failure = Result.Failure(error);
if (failure.IsFailure)
{
Console.WriteLine($"Error: {failure.Error.Code} - {failure.Error.Description}");
}
Working with Values
// Create a successful result with a value
Result<User> userResult = Result<User>.Success(new User { Name = "John" });
if (userResult.IsSuccess)
{
User user = userResult.Value;
Console.WriteLine($"User: {user.Name}");
}
// Create a failure result
Error error = new Error("USER_NOT_FOUND", "User does not exist");
Result<User> notFound = Result<User>.Failure(error);
// Implicit conversions make it even easier
Result<User> success = new User { Name = "Jane" }; // Automatically wraps in Success
Result<User> failure = new Error("SERVER_ERROR", "Database unavailable"); // Automatically wraps in Failure
Real-World Example
public Result<User> GetUserById(int userId)
{
if (userId <= 0)
{
return Result<User>.Failure(
new Error("INVALID_ID", "User ID must be positive")
);
}
User? user = _repository.Find(userId);
if (user is null)
{
return Result<User>.Failure(
new Error("USER_NOT_FOUND", $"User with ID {userId} not found")
);
}
return user; // Implicit conversion to Result<User>.Success(user)
}
// Usage
Result<User> result = GetUserById(123);
if (result.IsFailure)
{
Console.WriteLine($"Failed to get user: {result.Error.Description}");
return;
}
User user = result.Value;
Console.WriteLine($"Found user: {user.Name}");
API Reference
Result
The base class for operation results.
Properties
| Property | Type | Description |
|---|---|---|
IsSuccess |
bool |
Indicates whether the operation was successful |
IsFailure |
bool |
Indicates whether the operation failed |
Error |
Error |
The error associated with a failed result |
Methods
| Method | Returns | Description |
|---|---|---|
Success() |
Result |
Creates a successful result |
Failure(Error error) |
Result |
Creates a failed result with the specified error |
Result<T>
A generic result that returns a value on success.
Properties
| Property | Type | Description |
|---|---|---|
Value |
T |
The value of the successful operation |
(Inherits all properties from Result) |
Methods
| Method | Returns | Description |
|---|---|---|
Success(T value) |
Result<T> |
Creates a successful result with the specified value |
Failure(Error error) |
Result<T> |
Creates a failed result with the specified error |
Implicit Conversions
T→Result<T>: Creates a successful result containing the valueError→Result<T>: Creates a failed result containing the error
Error
Represents structured error information.
Properties
| Property | Type | Description |
|---|---|---|
Code |
string |
The error code identifier |
Description |
string |
Human-readable error description |
None |
static Error |
Represents no error (success state) |
Usage Patterns
Chaining Operations
Result<User> GetUser(int id) => /* ... */;
Result<Address> GetAddress(User user) => /* ... */;
Result<Location> GetLocation(Address address) => /* ... */
Result<Location> result = GetUser(userId)
.Bind(user => GetAddress(user))
.Bind(address => GetLocation(address));
Matching Results
string message = result.Match(
onSuccess: value => $"Success: {value}",
onFailure: error => $"Error: {error.Description}"
);
Error Aggregation
List<Error> errors = new();
// Collect errors from multiple operations
foreach (var item in items)
{
Result<ProcessedItem> result = ProcessItem(item);
if (result.IsFailure)
{
errors.Add(result.Error);
}
}
if (errors.Count > 0)
{
return Result.Failure(
new Error("MULTIPLE_ERRORS", $"{errors.Count} items failed to process")
);
}
License
This project is licensed under the Business Source License 1.1.
The license allows free commercial use while protecting the source code. The code will automatically convert to the MIT License on [Change Date], 3 years after the first publication.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Acknowledgments
Inspired by the Result Pattern popularized by Martin Fowler and the functional programming community.
Note: This library is in active development. API changes may occur before version 1.0.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.1-alpha | 146 | 12/31/2025 |
| 1.0.0-alpha | 125 | 12/31/2025 |
| 0.0.4-alpha | 212 | 12/25/2025 |
| 0.0.3 | 237 | 12/24/2025 |
| 0.0.1 | 211 | 12/22/2025 |
| 0.0.0-ge417d127dc | 203 | 12/24/2025 |