LfrlAnvil.Functional 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package LfrlAnvil.Functional --version 0.2.0                
NuGet\Install-Package LfrlAnvil.Functional -Version 0.2.0                
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.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LfrlAnvil.Functional --version 0.2.0                
#r "nuget: LfrlAnvil.Functional, 0.2.0"                
#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.0

// Install LfrlAnvil.Functional as a Cake Tool
#tool nuget:?package=LfrlAnvil.Functional&version=0.2.0                

(root) NuGet Badge

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 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.

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
0.2.1 108 6/16/2024
0.2.0 96 6/16/2024
0.1.1 104 5/29/2024
0.1.0 103 5/26/2024