Exemple #1
0
 /// <summary>
 /// Functor `map` operation
 /// </summary>
 public static Cont <r, b> Map <r, a, b>(this Cont <r, a> that, Func <a, b> f) =>
 Cont <r, b> .Create(k => that.Case(aˈ => k(f(aˈ))));
Exemple #2
0
 /// <summary>
 /// Put a function into a continuation, effectively running it
 /// </summary>
 public static r Run <r, a>(Func <a, r> f, Cont <r, a> cont) => cont.Case(f);
Exemple #3
0
 /// <summary>
 /// Execute continuation when argument type and return types are same
 /// </summary>
 public static r Uncont <r>(this Cont <r, r> that) => that.Case(Id);
Exemple #4
0
 /// <summary>
 /// Applicative functor lift
 /// </summary>
 public static Cont <r, c> Lift <r, a, b, c>(this Func <a, b, c> f, Cont <r, a> aˈ, Cont <r, b> bˈ) =>
 Cont <r, c> .Create(k => aˈ.Case(aa => bˈ.Case(bb => k(f(aa, bb)))));
Exemple #5
0
 /// <summary>
 /// Applies a function inside an applicative context (see Applicative functors)
 /// </summary>
 public static Cont <r, b> Ap <r, a, b>(this Cont <r, Func <a, b> > f, Cont <r, a> aˈ) =>
 Cont <r, b> .Create(k => aˈ.Case(aa => f.Case(ff => k(ff(aa)))));
Exemple #6
0
 /// <summary>
 /// Monad `join` operation
 /// </summary>
 public static Cont <r, a> Flatten <r, a>(this Cont <r, Cont <r, a> > that) =>
 Cont <r, a> .Create(k => that.Case(aˈ => aˈ.Case(k)));