Lachstec.Result
2.0.0
dotnet add package Lachstec.Result --version 2.0.0
NuGet\Install-Package Lachstec.Result -Version 2.0.0
<PackageReference Include="Lachstec.Result" Version="2.0.0" />
<PackageVersion Include="Lachstec.Result" Version="2.0.0" />
<PackageReference Include="Lachstec.Result" />
paket add Lachstec.Result --version 2.0.0
#r "nuget: Lachstec.Result, 2.0.0"
#:package Lachstec.Result@2.0.0
#addin nuget:?package=Lachstec.Result&version=2.0.0
#tool nuget:?package=Lachstec.Result&version=2.0.0
Lachstec.Result
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 Lachstec.Result
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 | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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. |
-
net6.0
- No dependencies.
-
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 |
---|---|---|
2.0.0 | 160 | 5/1/2025 |