LfrlAnvil.Functional
0.2.1
dotnet add package LfrlAnvil.Functional --version 0.2.1
NuGet\Install-Package LfrlAnvil.Functional -Version 0.2.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="LfrlAnvil.Functional" Version="0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LfrlAnvil.Functional --version 0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LfrlAnvil.Functional, 0.2.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.
// Install LfrlAnvil.Functional as a Cake Addin #addin nuget:?package=LfrlAnvil.Functional&version=0.2.1 // Install LfrlAnvil.Functional as a Cake Tool #tool nuget:?package=LfrlAnvil.Functional&version=0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
(root)
LfrlAnvil.Functional
This project contains a few functional programming functionalities.
Documentation
Technical documentation can be found here.
Examples
Following is an example of a Maybe
(or Option
) monad:
// creates a maybe instance with a value
var some = Maybe.Some( "foo" );
// creates a maybe instance without a value
var none = Maybe<string>.None;
// this will throw an exception, because the value is null
var _ = Maybe.Some( ( string? )null );
// this is the safe way to create a maybe instance from a nullable value
var safe = (( string? )null).ToMaybe();
// converts maybe of string to maybe of int, using provided 'some' and 'none' delegates
// the 'some' delegate will be invoked only when the source maybe has a value,
// otherwise the 'none' delegate will be invoked
var bindResult = safe.Bind( some: value => int.TryParse( value, out var r ) ? r : Maybe<int>.None, none: () => Maybe<int>.None );
// converts maybe of string to string, using provided 'some' and 'none' delegates
// the 'some' delegate will be invoked only when the source maybe has a value,
// otherwise the 'none' delegate will be invoked
var matchResult = safe.Match( some: value => value, none: () => string.Empty );
// gets an underlying value or returns the provided argument, if maybe does not have a value
// this is equivalent to the above 'Match' invocation
var result = safe.GetValueOrDefault( string.Empty );
There are other monads as well, like Either
, Erratic
(represents either a returned value or a thrown exception),
TypeCast
or Mutation
(represents a change of value). There is also the Nil
type, which represents a lack of value.
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- LfrlAnvil.Core (>= 0.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.