Functional.Toolkit.OptionType
1.0.10
dotnet add package Functional.Toolkit.OptionType --version 1.0.10
NuGet\Install-Package Functional.Toolkit.OptionType -Version 1.0.10
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="Functional.Toolkit.OptionType" Version="1.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Functional.Toolkit.OptionType" Version="1.0.10" />
<PackageReference Include="Functional.Toolkit.OptionType" />
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 Functional.Toolkit.OptionType --version 1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Functional.Toolkit.OptionType, 1.0.10"
#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 Functional.Toolkit.OptionType@1.0.10
#: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=Functional.Toolkit.OptionType&version=1.0.10
#tool nuget:?package=Functional.Toolkit.OptionType&version=1.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
🚀 Functional.Toolkit.OptionType
Functional.Toolkit.OptionType is a lightweight library that provides an implementation of the Option type in C#. The Option type is a functional programming concept that represents a value that may or may not be present. This can help reduce the number of null checks in your code, making it more robust and easier to reason about.
Here its just a few examples, check all the available extensions in the OptionExtensions.cs file
Usage
//Object Initialization
var option1 = Option.From((ClassForTest)null); //will automatically determine if its None or Some based on the generic type
var option2 = Option.From(new ClassForTest());
var option3 = Option.None<ClassForTest>();
var option4 = Option.Some(new ClassForTest());
...
//Sync
var maybeClass = await MaybeGetClass();
maybeClass
.WhenSome(value =>
{
Console.WriteLine($"Proceed doing something with the value: {value.Name}");
//It could be whatever you want, here you have the value of the type of the Option
//Example:
//Call another methods, write in the DB, Publish to a Service Bus, infinity...
})
.WhenNone(() =>
{
Console.WriteLine("Proceed as a fallback without the value");
//since the Option is None the value couldn't be found.
//Example:
//Write logs, alerts, whatever.
})
.WhenAny(maybeValue =>
{
Console.WriteLine("Despite having a value or not this will be execute and you can decide what to do.");
Console.WriteLine($"Does my object has a value? {maybeValue.HasValue}");
});
//Async
var maybeClassTask = MaybeGetClass();
var result = await maybeClassTask
.WhenSomeAsync(value =>
{
Console.WriteLine($"Proceed doing something with the value: {value.Name}");
return Task.CompletedTask;
})
.WhenNoneAsync(() =>
{
Console.WriteLine("Proceed as a fallback without the value");
return Task.CompletedTask;
}).WhenAnyAsync(maybeValue =>
{
Console.WriteLine($"Does my object has a value? {maybeValue.HasValue}");
});
| 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 was computed. 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 was computed. 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | 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.
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.