TinyResult 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TinyResult --version 1.0.0
                    
NuGet\Install-Package TinyResult -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TinyResult" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TinyResult" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TinyResult" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TinyResult --version 1.0.0
                    
#r "nuget: TinyResult, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TinyResult@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TinyResult&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TinyResult&version=1.0.0
                    
Install as a Cake Tool

TinyResult

A lightweight and powerful Result Pattern implementation for .NET 9. This library is designed to make error handling and validation operations cleaner and more readable.

Features

  • ✅ Result Pattern Implementation
  • ✅ Comprehensive error handling
  • ✅ Built-in validation support
  • ✅ Full async/await support
  • ✅ LINQ-style operations
  • ✅ Fluent API for chaining operations
  • ✅ Extensible structure
  • ✅ Lightweight design
  • ✅ .NET 9 Support

Requirements

  • .NET 9.0 or later

Installation

dotnet add package TinyResult

Quick Start

Basic Usage

// Creating a successful result
var success = Result<int>.Success(42);

// Creating a failed result
var failure = Result<int>.Failure(ErrorCode.NotFound, "Item not found");

// Pattern matching
var message = success.Match(
    value => $"Success: {value}",
    error => $"Error: {error.Message}"
);

// Chaining operations
var result = ResultPipeline<int>
    .Start(10)
    .Map(x => x * 2)
    .Validate(x => x > 0, ErrorCode.ValidationError, "Value must be positive")
    .OnSuccess(x => Console.WriteLine($"Value: {x}"))
    .OnFailure(error => Console.WriteLine($"Error: {error.Message}"))
    .Build();

Error Handling

// Creating detailed errors
var error = Error.Create(
    ErrorCode.ValidationError,
    "Invalid input",
    new Dictionary<string, object>
    {
        { "Field", "Email" },
        { "Value", "invalid-email" }
    }
);

// Exception handling
var result = Result.FromTry(
    () => int.Parse("not-a-number"),
    ex => Error.Create(ErrorCode.InternalError, "Failed to parse number", ex)
);

Validation

// Creating validation result
var validationResult = ValidationResult.Create()
    .AddError("Email", "Invalid email format")
    .AddError("Password", "Password too short");

// Using validation with Result
var result = Result<int>.Success(42)
    .Validate(value => value > 0, ErrorCode.ValidationError, "Value must be positive")
    .Validate(value => value < 100, ErrorCode.ValidationError, "Value must be less than 100");

Async Operations

// Async result creation
var asyncResult = await Result.FromTryAsync(
    async () => await GetDataAsync(),
    ex => Error.Create(ErrorCode.InternalError, "Failed to get data", ex)
);

// Async pipeline
var pipelineResult = await ResultPipeline<int>
    .Start(10)
    .ThenAsync(async x => await ProcessAsync(x))
    .MapAsync(async x => await TransformAsync(x))
    .BuildAsync();

Result Combination

// Combining two results
var result1 = Result<int>.Success(10);
var result2 = Result<int>.Success(20);

var combinedResult = Result.Combine(
    result1,
    result2,
    (value1, value2) => value1 + value2
);

// Combining multiple results
var results = new[]
{
    Result<int>.Success(1),
    Result<int>.Success(2),
    Result<int>.Success(3)
};

var combinedResults = Result.Combine(results);

Documentation

For more detailed information, please visit our documentation.

Contributing

We welcome contributions! Please see our Contributing Guide for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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 193 5/5/2025
1.0.0 207 4/17/2025