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
<PackageReference Include="Trarizon.Library.Functional" Version="1.0.4" />
<PackageVersion Include="Trarizon.Library.Functional" Version="1.0.4" />
<PackageReference Include="Trarizon.Library.Functional" />
paket add Trarizon.Library.Functional --version 1.0.4
#r "nuget: Trarizon.Library.Functional, 1.0.4"
#:package Trarizon.Library.Functional@1.0.4
#addin nuget:?package=Trarizon.Library.Functional&version=1.0.4
#tool nuget:?package=Trarizon.Library.Functional&version=1.0.4
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
HasValueValue: This property won't throw if this isNoneGetValueOrThrow()GetValueOrDefault(),GetValueOrDefault(T)TryGetValue(out T)GetValueRefOrDefaultRef()
Optional<T> has following members to chain
operator |oroperator ||Or()Cast<TResult>()so you can cast it to its interfaces of base typeMatch()returnTResultorvoidMatchValue()andMatchNone
Select()map valueBind()map value toOptional<TResult>SelectManay()is also provided, so you can use linq expression to do this
Zip()Where()filterToNullable()convert toNullable<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 returnNoneIEnumerable<T>.WhereSelect(Func<T, Optional<TResult>>) : IEnumerable<TRsult>LinqWhereandSelectIEnumerable<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 | Versions 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. |
-
.NETStandard 2.0
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
.NETStandard 2.1
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
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.