Funcfy 0.2.0
dotnet add package Funcfy --version 0.2.0
NuGet\Install-Package Funcfy -Version 0.2.0
<PackageReference Include="Funcfy" Version="0.2.0" />
<PackageVersion Include="Funcfy" Version="0.2.0" />
<PackageReference Include="Funcfy" />
paket add Funcfy --version 0.2.0
#r "nuget: Funcfy, 0.2.0"
#:package Funcfy@0.2.0
#addin nuget:?package=Funcfy&version=0.2.0
#tool nuget:?package=Funcfy&version=0.2.0
<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>
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
whenIsEmpty
istrue
returnsnull
for reference types or the default for value types. Always checkIsFull
first.
Contributing
- Fork the repo
- Create a feature branch (
git checkout -b feature/foo
) - Commit changes (
git commit -m 'feat: add foo'
) - Push to your branch (
git push origin feature/foo
) - Open a Pull Request to develop branch
Product | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.3.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.3.0)
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.