Funcfy 0.2.0

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

<p align="center"> <img
alt="funcfy - A lightweight, batteries-included functional programming toolkit for C#/.NET." src="https://github.com/leo-oliveira-eng/funcfy/blob/main/images/logo.png" height="400px" /> </p>

CI - Build & Test artifact CodeQL Dependabot Updates Prerelease Release codecov License NuGet Version

funcfy

A lightweight, batteries-included functional programming toolkit for C#/.NET.

Features

📋 Currying & partial application
🔄 Either, Maybe, Result types
📋 Functor, Applicative, Monad interfaces
📋 Lens utilities, compose, pipe

Getting Started

Install via NuGet:

dotnet add package Funcfy --version 0.1.0-alpha

Import the core namespace:

using Funcfy;

Example currying:

var add = Func.Curry((int x, int y) => x + y);
var add5 = add(5);
Console.WriteLine(add5(3));  // 8

Using Maybe<T>

The Maybe<T> type expresses optional values explicitly, avoiding null-reference surprises. Example:

  public class RepositoryAsync<Entity> : SpecificMethods<Entity>, IRepositoryAsync<Entity>
  {
  ...

  public async Task<Maybe<Entity>> FindAsync(int id)
      => await DbSet.FirstOrDefaultAsync(entity => entity.Id.Equals(id));
      
  ...
  }
      

The developer can act as follows when receiving the response:


  ...

      var entity = await EntityRepository.FindAsync(entityId);

      if (entity.IsEmpty)
          return response.WithError("Not found");

  ...

Creating Instances

  • Empty (no value):

    var empty = Maybe<int>.Empty();          // IsFull == false, IsEmpty == true
    
  • Full (with a value):

    var full = Maybe<string>.Full("hello");  // IsFull == true, Value == "hello"
    Maybe<int> also = 42;                      // implicit conversion wraps 42 as Full
    

Inspecting Values

Use IsFull or IsEmpty before accessing Value:

if (full.IsFull)
{
    Console.WriteLine(full.Value);
}
else
{
    Console.WriteLine("No value present.");
}

Conversion Operators

Thanks to the implicit operator, you can assign raw values directly:

Maybe<double> pi = 3.14;  // equivalent to Maybe<double>.Full(3.14)

⚠️ Important: Accessing Value when IsEmpty is true returns null for reference types or the default for value types. Always check IsFull first.

Contributing

  1. Fork the repo
  2. Create a feature branch (git checkout -b feature/foo)
  3. Commit changes (git commit -m 'feat: add foo')
  4. Push to your branch (git push origin feature/foo)
  5. Open a Pull Request to develop branch

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 (1)

Showing the top 1 NuGet packages that depend on Funcfy:

Package Downloads
DomAid

DomAid is a lightweight .NET library that simplifies building clean, maintainable domain layers using DDD principles and the Mediator pattern.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 266 6/3/2025
0.1.0 66 5/24/2025