CSharpEssentials.Maybe 3.0.1

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

CSharpEssentials.Maybe

CSharpEssentials.Maybe implements the Maybe (Option) monad for .NET. It provides a type-safe way to handle the presence or absence of a value without relying on null references, making your code more expressive and less prone to NullReferenceException.

🚀 Features

  • Explicit Null Safety: Maybe<T> represents a value that might be missing.
  • Functional API: Chain operations with Map, Bind, Where, and Match.
  • LINQ Support: Use Select, SelectMany, and Where in LINQ query syntax.
  • Async Support: First-class support for async workflows (MapAsync, BindAsync).
  • JSON Integration: Serialization support included.

📦 Installation

dotnet add package CSharpEssentials.Maybe

🛠 Usage

1. Creating Maybe

Wrap values to indicate they might be absent.

using CSharpEssentials.Maybe;

public Maybe<User> GetUser(int id)
{
    User? user = _repo.Find(id);
    return user; // Implicit conversion from T? to Maybe<T>
}

// Explicit creation
var maybeValue = Maybe.From(someValue);
var none = Maybe.None;

2. Functional Chaining

Transform values safely. If the value is missing, the operations are skipped.

string result = GetUser(1)
    .Where(u => u.IsActive)          // Filter
    .Map(u => u.Address)             // Transform
    .Map(a => a.City)
    .GetValueOrDefault("Unknown");   // Unwrap

3. LINQ Query Syntax

Use LINQ to compose multiple Maybe values.

var result = 
    from user in GetUser(1)
    from order in GetLatestOrder(user.Id)
    where order.Amount > 100
    select order.TrackingNumber;

// result is Maybe<string>

4. Matching (Unwrapping)

Handle both cases (Value vs None) explicitly.

GetUser(1).Match(
    some: user => Console.WriteLine($"Found: {user.Name}"),
    none: () => Console.WriteLine("User not found")
);

5. Async Workflow

Seamlessly work with async tasks.

public async Task<Maybe<Order>> ProcessAsync(int userId)
{
    return await GetUserAsync(userId)
        .BindAsync(user => GetOrderAsync(user.Id))
        .MapAsync(order => EnrichOrderAsync(order));
}
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 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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 (2)

Showing the top 2 NuGet packages that depend on CSharpEssentials.Maybe:

Package Downloads
CSharpEssentials

A comprehensive C# library enhancing functional programming capabilities with type-safe monads (Maybe, Result), discriminated unions (Any), and robust error handling. Features include: domain-driven design support, enhanced Entity Framework integration, testable time management, JSON utilities, and LINQ extensions. Built for modern C# development with focus on maintainability, testability, and functional programming principles.

CSharpEssentials.EntityFrameworkCore

Enhances Entity Framework Core with functional programming patterns and DDD-friendly features. Includes base entity classes, soft delete support, audit trails, query filters, optimistic concurrency, PostgreSQL integration, query performance monitoring, and domain event handling. Perfect for building maintainable and scalable data access layers in modern .NET applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.1 30 5/3/2026
3.0.0 30 5/3/2026
2.1.0 278 11/26/2025
2.0.9 254 9/30/2025
2.0.8 227 9/29/2025
2.0.7 225 9/29/2025
2.0.6 238 9/29/2025
2.0.5 232 9/29/2025
2.0.4 241 9/28/2025
2.0.3 224 9/28/2025
2.0.2 225 9/28/2025
2.0.1 234 9/28/2025
2.0.0 237 9/28/2025