Lachstec.SimpleResults 1.0.0

Suggested Alternatives

Lachstec.Result

dotnet add package Lachstec.SimpleResults --version 1.0.0
                    
NuGet\Install-Package Lachstec.SimpleResults -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="Lachstec.SimpleResults" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lachstec.SimpleResults" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Lachstec.SimpleResults" />
                    
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 Lachstec.SimpleResults --version 1.0.0
                    
#r "nuget: Lachstec.SimpleResults, 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 Lachstec.SimpleResults@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=Lachstec.SimpleResults&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Lachstec.SimpleResults&version=1.0.0
                    
Install as a Cake Tool

SimpleResults

Lightweight, zero-dependency library for safe and exception-free error-handling in C#. Heavily inspired by functional programming paradigms and Rust's Result type.

Table of Contents

Features

  • Strongly typed Result<TValue, TError> for operations that can succeed or fail, returning possibly different types of values.
  • Result<TError> for operations that can succeed or fail, but have no meaningful value in case of a success.
  • Combinators in a Fluent API style for chaining operations and performing control flow with results.
  • Zero dependencies, no external libraries required.

Installation

The library is published on NuGet. You can add it to your project using the following command:

dotnet add package SimpleResults

Usage

// Creating a result by calling a method that could fail, indicated by a result as return type
Result<int, string> result = DoSomething();

// Pattern-match on the returned result
int value = result.Match(
ok => ok * 2,
error => {
Console.WriteLine($"Error: {error}");
return -1;
});

Why use a Result type?

Many methods are designed to return a value or throw an exception. This can lead to bugs if the caller forgets to handle the exception. By using a Result type, you can ensure that the caller must handle both success and failure cases explicitly, thus ensuring that all possible cases get addressed. This Package helps you by providing a simple Result type with convenience functions to easily manipulate results and chain operations together.

Why another Result Library?

There are already a lot of libraries that provide the Result Pattern for C#, but most of them are complex and provide more than what is necessary. This library is designed to be simple and lightweight, with no dependencies, but still powerful enough to allow for ergonomic error handling.

Contributing

Contributions are welcome and much appreciated! If you think that you have a good idea for a new feature or a bug fix, please submit a pull request.

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.0 270 4/22/2025 1.0.0 is deprecated because it is no longer maintained.