Trarizon.Library.Functional 1.0.4

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

Trarizon.Library.Functional

Provides utilities for functional programming (Monads)

Monads

Optional<>, Result<,>, Either<,> are available, a non-generic type with same name is provided as factory(eg: Optional for Optional<T>, etc.).

All monads are value type

Optional & RefOptional

Use Optional.Of / Optional.None / Optional<T>.None to create a Optional<T> with or without value. We provider Optional.Create/OfNotNull/OfPredicate to help you quickly create a Optional<T> according to some predicate

With allows ref struct in .NET9, RefOptional<T> is provided as a Optional<T> for ref struct and has almost same functions with Optional<T>. You can use RefOptional.Of etc. to create RefOptional<T>, if your language version is C#14 or later, you can just use Optional.Of, and RefOptional<T> will be created if argument is ref struct.

Optional<T> and RefOptional<T> are implicitly convertable to each other, you can also use AsRef() and AsDeref() to convert between Optional<T> and RefOptional<T>

Optional<T> is implicited castable from a value

Optional<T> has following members to access data

  • HasValue
  • Value : This property won't throw if this is None
  • GetValueOrThrow()
  • GetValueOrDefault(), GetValueOrDefault(T)
  • TryGetValue(out T)
  • GetValueRefOrDefaultRef()

Optional<T> has following members to chain

  • operator | or operator ||
  • Or()
  • Cast<TResult>() so you can cast it to its interfaces of base type
  • Match() return TResult or void
    • MatchValue() and MatchNone
  • Select() map value
  • Bind() map value to Optional<TResult>
    • SelectManay() is also provided, so you can use linq expression to do this
  • Zip()
  • Where() filter
  • ToNullable() convert to Nullable<T>

Optional<T> has some methods related to IEnumerable<T>

  • IEnumerable<Optional<T>>.Collect(): Optional<IEnumerable<T>> returns the sequence if all optionals has value, else return None
  • IEnumerable<T>.WhereSelect(Func<T, Optional<TResult>>) : IEnumerable<TRsult> Linq Where and Select
  • IEnumerable<Optional<T>>.WhereHasValue() : IEnumerable<T> returns sequence contains values

You may notice that Optional.None returns a Optional.NoneBuilder, Result.Success() returns a Result.SuccessBuilder<T> etc. They can be implicitly converted to or use Build() to create a monad type.

I use this so that when I want to create a Optional.None, I don't have to specify the type of value like Optional.None<T>(), this works better on Result<T, TError>, as you can use Result.Success(1) to create a Success rather than Result.Success<int, string>(1), C# force you to write all type arguments if compiler don't know.

Also, all types are designed in value type, so I should avoid boxing and cannot use inheritance

Result

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 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.  net9.0 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Trarizon.Library.Functional:

Package Downloads
Trarizon.Library

Trarizon's personal library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 90 3/8/2026
1.0.3 189 11/24/2025
1.0.2 179 9/20/2025
1.0.1 238 8/24/2025
1.0.0 184 7/14/2025