Skip to main content

Functional - UnambitiousFx

Result, Maybe, and railway-oriented error handling for .NET โ€” zero-allocation and Native-AOT ready.

dotnet add package UnambitiousFx.Functional
Quick start
// Compose with railway-oriented programming
public Result<Order> PlaceOrder(OrderRequest request) =>
    Validate(request)               // Result<OrderRequest>
        .Bind(LoadCustomer)         // Result<Customer>
        .Ensure(c => c.IsActive,
            new ValidationFailure("Customer is inactive"))
        .Map(CreateOrder)           // Result<Order>
        .Tap(order => _log.Created(order.Id));

// Pattern match โ€” errors are values, not exceptions
var response = PlaceOrder(request).Match(
    success: order => Results.Ok(order),
    failure: error => Results.BadRequest(error.Message));

// Optionals without null
Maybe<User> user = _users.TryFind(id);
string name = user
    .Map(u => u.Name)
    .ValueOr("anonymous");

Why Functional?

๐Ÿš‚

Result & Railway

Model success and failure as one type. Chain Bind, Map, and Ensure โ€” the first failure short-circuits the rest. Errors are values, not exceptions.

๐ŸŽ

Maybe / Optionals

Represent "a value or nothing" without null. Compose with Map, Filter, and OrElse, then bridge to Result when you need a reason.

๐Ÿท๏ธ

Rich Failures

Typed failures โ€” validation, not-found, conflict, unauthorized โ€” each with a machine-readable code and attachable Metadata. Aggregate many into one.

โšก

Zero-Allocation & AOT

Core types are readonly structs with ValueTask-based async. Minimal heap traffic in hot paths and fully Native-AOT compatible.