This project provides the following monads:
- Maybe
- Try
This library is:
- netstandard2.0
- strong-name signed
- CLS compliant
This represents the Maybe (or Option) monad.
var m = Maybe.From("these pretzels are making me thirsty");
var n = Maybe.Nothing<int>();
var x = m.OrElse("yada yada yada"); // yields "these pretzels ..."
var y = n.OrElse(17); // yields 17
See full documentation for Maybe
;
This represents an exceptional monad that can be used to construct lazy chains of action and catch blocks.
var result = await Try
.Do(() => "I will succeed.")
.ThenAsync(async x => x + " Oh will you?")
.Then(_ => throw new InvalidOperationException())
.Catch<InvalidOperationException>(ex =>
{
Log.WriteError("Operation did not succeed");
return "failed";
});
See full documentation for Try
;
This represents the functional unit type.
var u = default(Unit);