Wrap.Either.Testing 2.0.0-beta.3

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

Wrap: Functional Monads for .NET

GitHub release (latest by date including pre-releases) Nuget GitHub<br/>Test Publish Codacy Badge

Functional monads for C#, to handle null values and failures without exceptions. Chain operations with method calls or LINQ query syntax (railway-oriented programming), with async support throughout.

Types

  • Maybe<T>: either Some<T> or None. Use it instead of null.
  • Result<T>: either Ok<T> or Failure. Use it instead of throwing exceptions.
  • Either<TLeft, TRight>: either Left<TLeft> or Right<TRight>.
  • Id<TId, TValue>: strongly typed IDs backed by int, uint, long, ulong or Guid.

Maybe<T>, Result<T> and Either<TLeft, TRight> are C# 15 union types. Each is a struct, so:

  • switch and is patterns work on the cases, and the compiler checks that a switch covers them all.
  • Wrapping a value in Some<T> or Ok<T> does not allocate.
  • They are never null. default(Maybe<T>) is None, and default(Result<T>) is a Failure.

Example

using Wrap;
using Wrap.Extensions;

static Result<int> ParseAge(string input) =>
    int.TryParse(input, out var age) && age >= 0
        ? age
        : R.Fail("Age must be a whole number of 0 or more.");

static string Describe(Result<int> age) =>
    age.Map(x => x + 1) switch
    {
        Ok<int>(var next) => $"Next year you'll be {next}.",
        Failure f => f.Message
    };

static string Greet(string? name) =>
    M.Wrap(name) // null becomes None
        .Map(x => $"Hello, {x}!")
        .Match(fNone: () => "Hello, stranger!", fSome: x => x);

View the Wiki for full documentation.

Packages

Package Contents
Wrap Everything: the types plus all extension methods (Bind, Map, Match, LINQ, async, JSON converters). Start here.
Wrap.Mvc ASP.NET Core MVC model binding for Wrap types.
Wrap.Caching Thread-safe caching that uses Wrap types.
Wrap.Id.Dapper Dapper type handlers for strongly typed IDs.
Wrap.Testing Helpers for unit tests (AssertSome, AssertOk, AssertFailure, value generators).

The core types are also published on their own: Wrap.Common, Wrap.Maybe, Wrap.Result, Wrap.Either and Wrap.Id, each with a matching .Testing package.

Requirements

Wrap 2 targets .NET 11 and needs C# 15, which comes with the .NET 11 SDK.

Wrap 1.x supports .NET 8, 9, 10 and 11, so you can stay on it without union types. It is in maintenance and gets fixes only.

History

Wrap brings together projects I have been working on since 2019. It started with a Result<T> implementation, which became Maybe (v10 in November 2025), and I decided it was best to have both.

At the same time I was maintaining StrongId (v8.5 in November 2024) so entity IDs didn't have to be primitives. I realised how much Result<T>, Maybe<T> and Id<T> had in common and brought them together in one library: Wrap.

Version 2 rebuilds the core types on the union types introduced in C# 15.

Licence

MIT

Copyright (c) 2019-2026 bfren (unless otherwise stated)

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Wrap.Either.Testing:

Package Downloads
Wrap.Testing

All.Testing library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0-beta.3 0 11/13/2026
2.0.0-beta.1 0 11/13/2026