Esempio n. 1
0
        //#region Traverse
        //public static IEnumerable<Cont<R, B>> Traverse<R, A, B>(this Cont<R, A> @this, Func<A, IEnumerable<B>> f) => @this.Fold(a => f(a).Map(Of<R, B>()));
        //public static Maybe<Cont<R, B>> Traverse<R, A, B>(this Cont<R, A> @this, Func<A, Maybe<B>> f) => @this.Fold<R, B>(a => f(a).Map(Of<R, B>()));
        //#endregion

        #region Callcc
        /// The callcc function; call with current continuation; is there to allow “escaping” from the current continuation.
        public static Cont <R, A> CallCC <R, A, B>(Func <Func <A, Cont <R, B> >, Cont <R, A> > f) => Cont <R, A> .Create(k => f(a => Cont <R, B> .Create(x => k(a))).Run(k));
Esempio n. 2
0
 public static Cont <R, B> Select <R, A, B>(this Cont <R, A> @this, Func <A, B> f) => Cont <R, B> .Create(k => @this.Run(a => k(f(a))));
Esempio n. 3
0
 public static Cont <R, B> FlatMap <R, A, B>(this Cont <R, A> @this, Func <A, Cont <R, B> > f) => Cont <R, B> .Create(k => @this.Run(a => f(a).Run(k)));
Esempio n. 4
0
 public static Cont <R, C> ToCont <R, A, B, C>(this Cont <R, A> @this, Cont <R, B> @that, Func <A, B, C> f) => Cont <R, C> .Create(k => @this.Run(a => that.Run(b => k(f(a, b)))));
Esempio n. 5
0
 public static Cont <R, D> ToCont <R, A, B, C, D>(this Cont <R, A> @this, Cont <R, B> @thatb, Cont <R, C> @thatc, Func <A, B, C, D> f) => Cont <R, D> .Create(k => @this.Run(a => @thatb.Run(b => @thatc.Run(c => k(f(a, b, c))))));
Esempio n. 6
0
 public static Cont <R, A> ToCont <R, A>(this A a) => Cont <R, A> .Create(k => k(a));
Esempio n. 7
0
 public static Cont <R, B> ToCont <R, A, B>(this Cont <R, A> @this, Func <A, B> f) => Cont <R, B> .Create(k => @this.Run(f.Compose(k)));
Esempio n. 8
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ˈ))));
Esempio n. 9
0
 /// <summary>
 /// Call with current continuation
 /// </summary>
 public static Cont <r, a> CallCC <r, a, b>(Func <Func <a, Cont <r, b> >, Cont <r, a> > f) =>
 Cont <r, a> .Create(k => f(aˈ => Cont <r, b> .Create(_ => k(aˈ))).Case(k));
Esempio n. 10
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)))));
Esempio n. 11
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)))));
Esempio n. 12
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)));