public static RWS <R, W, S, C> M <R, W, S, A, B, C>(RWS <R, W, S, A> ma, RWS <R, W, S, B> mb, Func <A, B, C> liftFn) where S : class { return(from a in ma from b in mb select liftFn(a, b)); }
/// <summary> /// Select Many /// </summary> public static RWS <R, W, S, V> SelectMany <R, W, S, T, U, V>( this RWS <R, W, S, T> self, Func <T, RWS <R, W, S, U> > bind, Func <T, U, V> project ) where S : class { if (bind == null) { throw new ArgumentNullException("bind"); } if (project == null) { throw new ArgumentNullException("project"); } return((R r, S s) => { var resT = self(r, s); var resU = bind(resT.Value).Invoke(r, resT.State ?? s); var resV = project(resT.Value, resU.Value); return RWSResult.Create <W, S, V>(resV, resT.Output.Concat(resU.Output), resU.State ?? resT.State ?? s); }); }
public static RWS <R, W, S, D> M <R, W, S, A, B, C, D>(RWS <R, W, S, A> ma, RWS <R, W, S, B> mb, RWS <R, W, S, C> mc, Func <A, B, C, D> liftFn) where S : class { return(from a in ma from b in mb from c in mc select liftFn(a, b, c)); }
public static RWS <R, W, S, R> Ask <R, W, S, T>(this RWS <R, W, S, T> self, Func <R, R> f) { if (f == null) { throw new ArgumentNullException("f"); } return((R r, S s) => RWSResult.Create(f(r), new W[0], s)); }
/// <summary> /// Select /// </summary> public static RWS <R, W, S, U> Select <R, W, S, T, U>(this RWS <R, W, S, T> self, Func <T, U> select) where S : class { if (select == null) { throw new ArgumentNullException("select"); } return((R r, S s) => { var resT = self(r, s); var resU = select(resT.Value); return RWSResult.Create <W, S, U>(resU, resT.Output, resT.State ?? s); }); }
public static RWS <R, W, S, U> M <R, W, S, T, U>(RWS <R, W, S, T> m, Func <T, U> liftFn) where S : class { return(from v in m select liftFn(v)); }
public static RWS <R, W, S, IO <U> > IO <R, W, S, T, U>(RWS <R, W, S, IO <T> > m, Func <T, U> liftFn) where S : class { return(from v in m select Lift.M(v, liftFn)); }
/// <summary> /// Memoize the result /// </summary> public static Func <RWSResult <W, S, T> > Memo <R, W, S, T>(this RWS <R, W, S, T> self, R r, S s) { var res = self(r, s); return(() => res); }
public static RWS <R, W, S, R> Ask <R, W, S, T>(this RWS <R, W, S, T> self) { return((R r, S s) => RWSResult.Create(r, new W[0], s)); }