SoftwareMadeSimple.SimpleResults.Functional
1.0.0
See the version list below for details.
dotnet add package SoftwareMadeSimple.SimpleResults.Functional --version 1.0.0
NuGet\Install-Package SoftwareMadeSimple.SimpleResults.Functional -Version 1.0.0
<PackageReference Include="SoftwareMadeSimple.SimpleResults.Functional" Version="1.0.0" />
<PackageVersion Include="SoftwareMadeSimple.SimpleResults.Functional" Version="1.0.0" />
<PackageReference Include="SoftwareMadeSimple.SimpleResults.Functional" />
paket add SoftwareMadeSimple.SimpleResults.Functional --version 1.0.0
#r "nuget: SoftwareMadeSimple.SimpleResults.Functional, 1.0.0"
#:package SoftwareMadeSimple.SimpleResults.Functional@1.0.0
#addin nuget:?package=SoftwareMadeSimple.SimpleResults.Functional&version=1.0.0
#tool nuget:?package=SoftwareMadeSimple.SimpleResults.Functional&version=1.0.0
SimpleResults.Functional
Functional applicative extensions for SoftwareMadeSimple.SimpleResults, providing Lift and Apply with error accumulation.
Installation
dotnet add package SoftwareMadeSimple.SimpleResults.Functional
Why?
When validating multiple fields independently, you typically want to collect all errors rather than short-circuiting on the first failure. The applicative pattern enables exactly this � validate each field separately, then combine the results while accumulating every error.
Usage
Lift & Apply
Use Lift to wrap a function into a Result, then chain Apply calls to feed in each validated argument. If any argument fails, all errors are accumulated.
using SoftwareMadeSimple.SimpleResults;
using SoftwareMadeSimple.SimpleResults.Functional;
record Person(string Name, int Age);
Result<string, ValidationErrors> nameResult = ValidateName(input.Name);
Result<int, ValidationErrors> ageResult = ValidateAge(input.Age);
var result =
LiftResult<ValidationErrors>
.Lift((string name, int age) => new Person(name, age))
.Apply(nameResult)
.Apply(ageResult);
if (result.IsSuccess)
{
Person person = result.Value;
// use person
}
else
{
IEnumerable<ValidationError> errors = result.Error;
// all validation errors are collected here
}
Error accumulation
Unlike monadic Bind (which short-circuits on the first error), Apply runs every validation and collects all failures:
Result<string, ValidationErrors> nameResult = new List<ValidationError>
{
new("Name is required"),
new("Name must be at least 2 characters")
};
Result<int, ValidationErrors> ageResult = new List<ValidationError>
{
new("Age must be positive")
};
var result =
LiftResult<ValidationErrors>
.Lift((string name, int age) => new Person(name, age))
.Apply(nameResult)
.Apply(ageResult);
// result.Error contains all 3 validation errors
Functions with more parameters
Lift supports functions with up to 16 parameters. Each additional parameter is applied with another .Apply() call:
record Address(string Street, string City, string Zip);
var result =
LiftResult<ValidationErrors>
.Lift((string street, string city, string zip) => new Address(street, city, zip))
.Apply(streetResult)
.Apply(cityResult)
.Apply(zipResult);
Requirements
- .NET 10+
- SoftwareMadeSimple.SimpleResults 1.1.0+
License
| 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
- SoftwareMadeSimple.SimpleResults (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.