FunctionalConcepts 6.0.1

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

FunctionalConcepts

FunctionalConcepts é uma biblioteca .NET (net6.0) que traz composição funcional e uniões discriminadas para C#, com foco em fluxos explícitos, tratamento previsível de falhas, e evitar throw como controle de fluxo no domínio.

Tipos principais do pacote:

  • Result<TEntity> — sucesso (TEntity) ou falha (BaseError)
  • Option<T>Some(T) ou None
  • Choice<TLeft, TRight>Left, Right ou Bottom (estado inválido)

Além disso, a biblioteca inclui erros tipados (ex.: NotFoundError, InvalidObjectError, etc.) e utilitários para criação de erros via ErrorHelper.


Target Framework

  • .NET 6.0

Instalação

dotnet add package FunctionalConcepts

Começando rápido

Result<TEntity>

Criação (conversões implícitas reais do código):

using FunctionalConcepts.Errors;
using FunctionalConcepts.Results;

// sucesso
Result<int> ok = 10;

// falha via tupla -> BaseError (implicit)
Result<int> fail = (404, "not found");

// falha via BaseError
BaseError err = (500, "error");
Result<int> fail2 = err;

Consumindo com Match:

string msg = ok.Match(
    some => $"value={some}",
    error => $"error={error.Code} {error.Message}"
);

Option<T>

using FunctionalConcepts.Options;

Option<string> some = "value";
Option<string> none = NoneType.Value;

var text = some.Match(v => v, () => "none");

FailWhen retorna Result<T> e, se for None, vira NotFoundError("object not found") por padrão:

using FunctionalConcepts.Errors;
using FunctionalConcepts.Options;

Option<string> opt = NoneType.Value;

var r = opt.FailWhen(
    v => v.Length < 5,
    (InvalidObjectError)"too short"
);

// r é Fail com NotFoundError("object not found")

Choice<TLeft,TRight>

using FunctionalConcepts.Choices;

Choice<string, int> left = "FunctionalConcepts";
Choice<string, int> right = 123;

var x = left.Match(l => l.Length, r => r);

Choice também pode ficar em estado Bottom. Em Bottom, Match retorna default.


Documentação

Veja:

  • docs/index.md (índice)
  • docs/api-reference.md (referência completa, método por método)

Build e testes

dotnet build
dotnet test

Licença

GPL-3.0

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 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.
  • net6.0

    • No dependencies.

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
6.0.1 95 2/16/2026
6.0.0.4 306 8/16/2024
6.0.0.3 203 8/14/2024
6.0.0.2 202 7/20/2024
6.0.0.1 194 6/20/2024
6.0.0 189 6/20/2024
1.0.0 190 6/17/2024

Versão 6.0.1.0 Extensions methods for fluency approach