dotMaybe 0.1.0
See the version list below for details.
dotnet add package dotMaybe --version 0.1.0
NuGet\Install-Package dotMaybe -Version 0.1.0
<PackageReference Include="dotMaybe" Version="0.1.0" />
paket add dotMaybe --version 0.1.0
#r "nuget: dotMaybe, 0.1.0"
// Install dotMaybe as a Cake Addin #addin nuget:?package=dotMaybe&version=0.1.0 // Install dotMaybe as a Cake Tool #tool nuget:?package=dotMaybe&version=0.1.0
dotMaybe - The Maybe Monad for .NET
dotMaybe is a lightweight, intuitive implementation of the Maybe monad for .NET. It simplifies working with optional values, eliminating null reference exceptions and promoting a more functional, declarative programming style.
Give it a star ⭐ !
If you find this project valuable, please consider giving it a star! Your support helps others discover this work and encourages further development.
How to use
Creation
Maybe<string> someMaybe = Some.With("Hello, World!");
Maybe<string> noneMaybe = None.OfType<string>();
Retrieving value
int someValue = someMaybe.Match(none: () => -1, some: v => v.Length); // 13
int noneValue = noneMaybe.Match(none: () => -1, some: v => v.Length); // -1
Chaining operations
someMaybe
.Map(v => v.Length) // Maybe<int> of 13
.Bind(v => v > 20 ? Some.With(v) : None.OfType<int>()); // Maybe<int> of None
noneMaybe
.Map(v => v.Length) // Maybe<int> of None
.Bind(v => v > 20 ? Some.With(v) : None.OfType<int>()); // Maybe<int> of None
Query syntax
// Execute function if all maybes contain value
Maybe<int> finalSomeMaybe =
from v1 in someMaybe
from v2 in Some.With("Hello, World!")
from v3 in Some.With("Hello, World!")
let v4 = "Hello, World!"
select v1.Length + v2.Length + v3.Length + v4.Length; // Maybe<int> of 52
// Returns None when any Maybe don't contain value
Result<int> finalNoneMaybe =
from v1 in noneMaybe
from v2 in Some.With("Hello, World!")
from v3 in None.OfType<string>()
let v4 = "Hello, World!"
select v1.Length + v2.Length + v3.Length + v4.Length; // Maybe<int> of none
Contribution
If you would like to contribute to this project, check out CONTRIBUTING file.
License
This project is licensed under the terms of the MIT license.
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. |
.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 was computed. |
.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
- 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.