Skip to content

Monadic value

Leonid Gordo edited this page Oct 16, 2017 · 1 revision

Monadic value extensions

Map function

This call maps given monadic value to the given function.

var m = 5.ToM();
var n = m.Map(x => x * 2.0);

--> output: n is double and equals to 10.0

Or even maps to the number of functions.

 var m = 5.ToM();
 var n = m.Map(x => x * 2, x => x + 2);
 
 --> output: n is integer and equals to 12

Unwrap function

Unwraps all nested monadic values and extracts the plain value.

var wrappedValue = new TrackValue<int>(10).ToMaybe().ToM();
var result = wrappedValue.UnwrapAll<int>();

The function throws an InvalidCastException if it fails to find the valid package of the monadic values.

var wrappedValue = "hello";
var result = wrappedValue.UnwrapAll<int>(); // <-- will throw an exception
Clone this wiki locally