Tp.Core.Functional contains implementations of Maybe monad, Try monad and Either type.
Maybe monad is an implementation of Option type. It represents encapsulation of an optional value; e.g. it is used as the return type of functions which may or may not return a meaningful value when they are applied.
Usages:
var i = Maybe.Just(1); // Create a value
var m = i.Select(x=>x*2); // map value, result is Just(2)
var f = m.Where(x=>x%2==1); // filter value, result is Nothing
var n = m.Bind(x=>Maybe.Just(2*x)) // flatMap (or bind) value, result is Just(4)
Tp.Functional.Core does not require to specify a type of Maybe.Nothing
:
Maybe<int> n = Maybe.Nothing;
Maybe<int> m = Maybe<int>.Nothing;
n == m; // True
See more here
Either type represents disjoint union of two values:
var left = Either.CreateLeft<int,string>(1);
var right = Either.CreateRight<int,string>("string");
See more here
A Try wraps a computation that could either result in a value or in an exception being thrown:
var tryResult = Try.Create(()=>int.Parse(value));
var m = try.Select(x=>x*2);
See more here