AStarDev.FunctionalParadigm
0.1.4
dotnet add package AStarDev.FunctionalParadigm --version 0.1.4
NuGet\Install-Package AStarDev.FunctionalParadigm -Version 0.1.4
<PackageReference Include="AStarDev.FunctionalParadigm" Version="0.1.4" />
<PackageVersion Include="AStarDev.FunctionalParadigm" Version="0.1.4" />
<PackageReference Include="AStarDev.FunctionalParadigm" />
paket add AStarDev.FunctionalParadigm --version 0.1.4
#r "nuget: AStarDev.FunctionalParadigm, 0.1.4"
#:package AStarDev.FunctionalParadigm@0.1.4
#addin nuget:?package=AStarDev.FunctionalParadigm&version=0.1.4
#tool nuget:?package=AStarDev.FunctionalParadigm&version=0.1.4
AStarDev.FunctionalParadigm
Functional programming building blocks for .NET: explicit success/failure, optional values and validation, with no null returns and no exceptions for expected failures.
This package is largely a port of AStar.Dev.Functional.Extensions.
Installation
dotnet add package AStarDev.FunctionalParadigm
All types live in the AStarDev.FunctionalParadigm namespace:
using AStarDev.FunctionalParadigm;
Types
| Type | Purpose |
|---|---|
Result<TResult, TError> |
An operation that either succeeded (Ok) or failed (Fail) with a typed error. |
Option<T> |
A value that is either present (Some) or absent (None). Use instead of returning null. |
Validation<T> |
Either Valid or Invalid with a list of ValidationErrors, so every problem is reported at once. |
Exceptional<T> |
Wraps code that may throw: Success or Failure carrying the Exception. |
Unit |
A "no value" type for use where a generic type argument is required. |
Result
Result<int, string> parsed = int.TryParse(input, out var number)
? Result.Success<int, string>(number)
: Result.Failure<int, string>("Not a number");
string message = parsed
.Map(value => value * 2)
.Bind(value => value > 100
? Result.Failure<int, string>("Too large")
: Result.Success<int, string>(value))
.Match(
onSuccess: value => $"Result: {value}",
onFailure: error => $"Error: {error}");
Async chains work directly on Task<Result<,>> and ValueTask<Result<,>>, so there is no need to await into a variable first:
string message = await service.GetAsync(cancellationToken)
.BindAsync(item => service.EnrichAsync(item))
.MatchAsync(
onSuccess: item => Task.FromResult($"Loaded {item}"),
onFailure: error => Task.FromResult($"Failed: {error}"));
Other helpers include MapAsync, Tap/TapAsync, TapError, OrElseAsync and Ensure/EnsureAsync. RetryExtensions.RetryOnceAsync retries a failed Result operation once.
Option
Option<User> user = Option.Some(currentUser);
Option<User> nobody = Option.None<User>();
string name = user
.Filter(candidate => candidate.IsActive)
.Map(candidate => candidate.Name)
.MapOrDefault(value => value, "Unknown");
Result<User, string> asResult = nobody.ToResult(() => "User not found");
ToOption() converts nullable and reference values, and Values() / Choose(...) filter collections of options.
Validation
Validation<string> name = string.IsNullOrWhiteSpace(input)
? Validation.Invalid<string>(new ValidationError("Name", "Name is required"))
: Validation.Valid(input);
Result<string, string> asResult = name.ToResult(errors => string.Join("; ", errors.Select(error => error.Message)));
Use Apply and Combine to gather the errors from several validations into one result.
Exceptional
Exceptional<string> content = Exceptional.Run(() => File.ReadAllText(path));
Exceptional<string> asyncContent = await Exceptional.RunAsync(() => File.ReadAllTextAsync(path));
Pipe and compose
int length = "hello".Pipe(text => text.ToUpperInvariant()).Pipe(text => text.Length);
Pipe, PipeAsync, Tap and Compose support small, readable pipelines.
Notes
- Async extension methods use
ConfigureAwait(false), so they are safe to call from contexts with a synchronization context. - XML documentation ships with the package for IntelliSense.
License
MIT. Source and issues: https://github.com/astar-development/astar-dev-mono/tree/main/packages/core
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AStarDev.FunctionalParadigm:
| Package | Downloads |
|---|---|
|
AStarDev.InfrastructureAppDb
Shared EF Core AppDbContext, entities, configuration and migrations for the AStar OneDrive Sync / Wallpaper Scraper desktop apps. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.4 | 117 | 10/6/2026 |
v0.1.4 fix(functional-paradigm): remove duplicate README pack item
v0.1.3 fix(functional-paradigm): remove duplicate README pack item
v0.1.2 Add README and update ResultExtensions
v0.1.1 Fix for async extension methods to use ConfigureAwait(false) to avoid deadlocks in certain contexts.
v0.1.0 Initial release - largely a port of the existing functional programming utilities: AStar.Dev.Functional.Extensions.