FunctionalKit 8.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package FunctionalKit --version 8.0.0
                    
NuGet\Install-Package FunctionalKit -Version 8.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="FunctionalKit" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FunctionalKit" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FunctionalKit" />
                    
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 FunctionalKit --version 8.0.0
                    
#r "nuget: FunctionalKit, 8.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 FunctionalKit@8.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=FunctionalKit&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FunctionalKit&version=8.0.0
                    
Install as a Cake Tool

FunctionalKit

License .NET NuGet

A comprehensive functional programming library for .NET 8+ that brings the power of functional patterns to C#. FunctionalKit provides robust implementations of Optional, Result, Either patterns, along with a powerful messaging system that serves as an excellent alternative to MediatR.

🚀 Why FunctionalKit?

  • Type Safety: Eliminate null reference exceptions with Optional pattern
  • Error Handling: Robust error handling with Result and Either patterns
  • Railway Programming: Chain operations elegantly with built-in failure handling
  • Messaging System: Clean CQRS implementation with pipeline behaviors
  • Performance: Optimized readonly structs with minimal allocations
  • Async First: Full async/await support throughout the library
  • Rich Extensions: Over 100 extension methods for functional programming

📦 Installation

# Package Manager
Install-Package FunctionalKit

# .NET CLI
dotnet add package FunctionalKit

# PackageReference
<PackageReference Include="FunctionalKit" Version="1.0.0" />

⚡ Quick Start

// Add to Program.cs or Startup.cs
services.AddFunctionalKit(Assembly.GetExecutingAssembly());

// Or with behaviors
services.AddFunctionalKit(options =>
{
    options.EnableLogging = true;
    options.EnableValidation = true;
    options.EnablePerformanceMonitoring = true;
}, Assembly.GetExecutingAssembly());

🏗️ Core Features

🎯 Functional Types

  • Optional<T> - Safe null handling like Java's Optional
  • Result<T> - Railway-oriented programming for error handling
  • Either<TLeft, TRight> - Union types for representing alternatives
  • Validation<T> - Accumulate multiple validation errors

📨 Messaging System

  • IMessenger - Central messaging interface (MediatR alternative)
  • Commands & Queries - CQRS pattern implementation
  • Pipeline Behaviors - Cross-cutting concerns (logging, validation, caching)
  • Notifications - Pub/sub pattern support

🛠️ Advanced Features

  • Railway Programming - Chainable operations with failure handling
  • Pattern Matching - Functional pattern matching utilities
  • Circuit Breaker - Fault tolerance for external services
  • Retry Logic - Configurable retry mechanisms
  • Performance Monitoring - Built-in query performance tracking

📋 Examples

Optional Pattern

// Safe operations without null checks
var user = users.FirstOrNone(u => u.Id == userId)
    .Map(u => u.ToDto())
    .Filter(dto => dto.IsActive)
    .OrElse(() => GetDefaultUser());

Result Pattern

// Railway-oriented programming
var result = await ProcessOrderAsync(request)
    .Then(ValidateInventory)
    .Then(CalculateTotal)
    .Then(ProcessPayment)
    .ThenDo(order => PublishEvent(order));

Messaging System

// Clean CQRS implementation
public record GetUserQuery(int Id) : IQuery<User>;

public class GetUserHandler : IQueryHandler<GetUserQuery, User>
{
    public async Task<User> HandleAsync(GetUserQuery query, CancellationToken ct = default)
    {
        return await userRepository.GetByIdAsync(query.Id);
    }
}

// Usage
var user = await messenger.QueryAsync(new GetUserQuery(123));

🏆 Benefits

Type Safety

  • Eliminate NullReferenceException with Optional pattern
  • Compile-time error handling with Result pattern
  • Strong typing throughout the library

Performance

  • Readonly structs for minimal allocations
  • Reflection caching for messaging system
  • Optimized async operations with ConfigureAwait(false)

Developer Experience

  • Fluent APIs for readable code
  • Comprehensive documentation
  • Rich IntelliSense support
  • Extensive examples and guides

Enterprise Ready

  • Circuit breaker for fault tolerance
  • Performance monitoring and logging
  • Configurable pipeline behaviors
  • Robust error handling

📚 Documentation

🎯 Use Cases

Web APIs

[HttpGet("{id}")]
public async Task<ActionResult<User>> GetUser(int id)
{
    var result = await messenger.QueryAsync(new GetUserQuery(id));
    return result.Match(
        onSuccess: user => Ok(user),
        onFailure: error => NotFound(error)
    );
}

Data Processing

var results = await inputData
    .Select(ProcessItem)
    .Where(r => r.IsSuccess)
    .Select(r => r.Value)
    .Batch(100)
    .Select(batch => ProcessBatch(batch))
    .CombineResults();

Validation

public Validation<CreateUserRequest> ValidateRequest(CreateUserRequest request)
{
    return ValidateName(request.Name)
        .Combine(ValidateEmail(request.Email), (n, e) => n)
        .Combine(ValidateAge(request.Age), (ne, a) => request);
}

🔧 Configuration

Basic Setup

services.AddFunctionalKit(Assembly.GetExecutingAssembly());

Advanced Configuration

services.AddFunctionalKit(options =>
{
    options.EnableLogging = true;
    options.EnableValidation = true;
    options.EnableCaching = true;
    options.EnablePerformanceMonitoring = true;
    options.SlowQueryThresholdMs = 1000;
    options.EnableRetry = true;
    options.MaxRetries = 3;
}, Assembly.GetExecutingAssembly());

Individual Behaviors

services.AddFunctionalKitLogging();
services.AddFunctionalKitValidation();
services.AddFunctionalKitCaching();
services.AddFunctionalKitCircuitBreaker(failureThreshold: 5);

🏃‍♂️ Performance

FunctionalKit is designed for high performance:

  • Zero allocation for most operations using readonly structs
  • Reflection caching for messaging system reduces overhead
  • Memory efficient collection operations
  • Optimized async operations throughout

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

git clone https://github.com/your-repo/FunctionalKit.git
cd FunctionalKit
dotnet restore
dotnet build
dotnet test

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🙏 Acknowledgments

  • Inspired by functional programming languages like F#, Haskell, and Scala
  • Railway-oriented programming concept by Scott Wlaschin
  • Optional pattern from Java and other languages
  • Community feedback and contributions

📞 Support


Made with ❤️ for the .NET community

Product Compatible and additional computed target framework versions.
.NET 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. 
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
8.1.0 186 7/20/2025
8.0.0 18 7/19/2025

Initial release of FunctionalKit v1.0.0
           - Optional<T> pattern for null-safe operations
           - Result<T> pattern for error handling without exceptions
           - Either<TLeft, TRight> for union types
           - Validation<T> for error accumulation
           - Complete CQRS messaging system with pipeline behaviors
           - Railway-oriented programming support
           - Comprehensive extension methods library