MrDevRobot.ErrorOr.Extensions 1.0.0

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

MrDevRobot.ErrorOr.Extensions

Extension methods for the ErrorOr library, adding ValueTask support, functional aliases (Map/Bind), and Combine/Collect for error aggregation.

NuGet

Installation

dotnet add package MrDevRobot.ErrorOr.Extensions

The package targets netstandard2.0 and net8.0, so it works with .NET Framework 4.6.1+, .NET Core 2.0+, and .NET 5+.

The namespace is ErrorOr — the same as the base library. No additional using directives needed.

Features

1. ValueTask Support

Full ValueTask<ErrorOr<T>> support for all fluent operations, mirroring the existing Task<ErrorOr<T>> extensions.

Three categories of overloads are provided for each operation:

Receiver Sync callback Task callback ValueTask callback
ValueTask<ErrorOr<T>>
ErrorOr<T> — (already in base lib) — (already in base lib)

Operations covered: Then, ThenDo, ThenAsync, ThenDoAsync, Match, MatchFirst, MatchAsync, MatchFirstAsync, Switch, SwitchFirst, SwitchAsync, SwitchFirstAsync, Else, ElseAsync, FailIf, FailIfAsync.

Example — chaining with ValueTask
ValueTask<ErrorOr<User>> GetUserAsync(int id) => ...;
ValueTask<ErrorOr<Order>> GetLastOrderAsync(User user) => ...;

ErrorOr<decimal> result = await GetUserAsync(42)
    .ThenAsync(user => GetLastOrderAsync(user))
    .Then(order => order.Total);
Example — ValueTask callback on ErrorOr<T>
ErrorOr<int> errorOr = 42;

ErrorOr<string> result = await errorOr
    .ThenAsync(value => new ValueTask<string>(value.ToString()));

2. Functional Aliases — Map / Bind

Aliases for developers familiar with functional programming terminology:

Alias Equivalent Semantics
Map(Func<T, TNext>) Then Transform the value
Bind(Func<T, ErrorOr<TNext>>) Then Chain an operation that may fail
MapAsync(Func<T, Task<TNext>>) ThenAsync Async transform
BindAsync(Func<T, Task<ErrorOr<TNext>>>) ThenAsync Async chain
MapAsync(Func<T, ValueTask<TNext>>) ThenAsync ValueTask async transform
BindAsync(Func<T, ValueTask<ErrorOr<TNext>>>) ThenAsync ValueTask async chain

All aliases are available on ErrorOr<T>, Task<ErrorOr<T>>, and ValueTask<ErrorOr<T>>.

Example
ErrorOr<string> name = "Alice";

ErrorOr<int> length = name.Map(n => n.Length);

ErrorOr<User> user = name.Bind(n => FindUser(n)); // FindUser returns ErrorOr<User>

3. Combine / Collect — Error Aggregation

Aggregate multiple ErrorOr<T> results, collecting all errors instead of short-circuiting at the first failure.

Combine — heterogeneous types

Merge 2–6 ErrorOr<T> of different types into a named tuple:

ErrorOr<string> nameResult = ValidateName(input.Name);
ErrorOr<int> ageResult = ValidateAge(input.Age);
ErrorOr<string> emailResult = ValidateEmail(input.Email);

ErrorOr<(string First, int Second, string Third)> combined =
    nameResult.Combine(ageResult, emailResult);

// If all valid:
var (name, age, email) = combined.Value;

// If any failed: combined.Errors contains ALL validation errors
Collect — homogeneous type

Merge a sequence of ErrorOr<T> into a single ErrorOr<List<T>>:

var validations = new[]
{
    ValidateField("name", input.Name),
    ValidateField("email", input.Email),
    ValidateField("phone", input.Phone),
};

ErrorOr<List<string>> result = validations.Collect();
// result.Value is List<string> with all valid values
// result.Errors contains every error from every failed validation

API Reference

ValueTask Extensions (ErrorOrValueTaskExtensions)

File Methods
ErrorOrValueTaskExtensions.Then.cs Then (2), ThenDo (1), ThenAsync (6), ThenDoAsync (2)
ErrorOrValueTaskExtensions.Match.cs Match (1), MatchFirst (1), MatchAsync (4), MatchFirstAsync (4)
ErrorOrValueTaskExtensions.Switch.cs Switch (1), SwitchFirst (1), SwitchAsync (4), SwitchFirstAsync (4)
ErrorOrValueTaskExtensions.Else.cs Else (5), ElseAsync (10)
ErrorOrValueTaskExtensions.FailIf.cs FailIf (2), FailIfAsync (6)

Functional Aliases (ErrorOrMapBindExtensions)

Method Overloads
Map 3 (ErrorOr, Task, ValueTask receivers × sync callback)
Bind 3 (ErrorOr, Task, ValueTask receivers × sync callback)
MapAsync 5 (Task + ValueTask callbacks on all receivers)
BindAsync 5 (Task + ValueTask callbacks on all receivers)

Combine / Collect (ErrorOrCombineExtensions)

Method Description
Combine<T1, T2> 2 ErrorOrErrorOr<(T1 First, T2 Second)>
Combine<T1, T2, T3> 3 ErrorOrErrorOr<(T1 First, T2 Second, T3 Third)>
Combine<T1, T2, T3, T4> 4 ErrorOrErrorOr<(..., T4 Fourth)>
Combine<T1, T2, T3, T4, T5> 5 ErrorOrErrorOr<(..., T5 Fifth)>
Combine<T1, T2, T3, T4, T5, T6> 6 ErrorOrErrorOr<(..., T6 Sixth)>
Collect<T> IEnumerable<ErrorOr<T>>ErrorOr<List<T>>

Compatibility

Target Min Version
.NET Standard 2.0 .NET Framework 4.6.1, .NET Core 2.0
.NET 8.0 .NET 8.0

Depends on:

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 is compatible.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 123 4/12/2026