CSharpEssentials.Maybe
3.0.1
dotnet add package CSharpEssentials.Maybe --version 3.0.1
NuGet\Install-Package CSharpEssentials.Maybe -Version 3.0.1
<PackageReference Include="CSharpEssentials.Maybe" Version="3.0.1" />
<PackageVersion Include="CSharpEssentials.Maybe" Version="3.0.1" />
<PackageReference Include="CSharpEssentials.Maybe" />
paket add CSharpEssentials.Maybe --version 3.0.1
#r "nuget: CSharpEssentials.Maybe, 3.0.1"
#:package CSharpEssentials.Maybe@3.0.1
#addin nuget:?package=CSharpEssentials.Maybe&version=3.0.1
#tool nuget:?package=CSharpEssentials.Maybe&version=3.0.1
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, andMatch. - LINQ Support: Use
Select,SelectMany, andWherein 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 | Versions 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. |
-
.NETStandard 2.1
- CSharpEssentials.Errors (>= 3.0.1)
- CSharpEssentials.Results (>= 3.0.1)
- System.Memory (>= 4.5.5)
- System.Text.Json (>= 8.0.5)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net9.0
- CSharpEssentials.Errors (>= 3.0.1)
- CSharpEssentials.Results (>= 3.0.1)
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.