示例#1
0
 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));
 }
示例#2
0
文件: RWS.cs 项目: uri65/csharp-monad
        /// <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);
            });
        }
示例#3
0
 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));
 }
示例#4
0
文件: RWS.cs 项目: uri65/csharp-monad
 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));
 }
示例#5
0
文件: RWS.cs 项目: uri65/csharp-monad
 /// <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);
     });
 }
示例#6
0
 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));
 }
示例#7
0
 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));
 }
示例#8
0
文件: RWS.cs 项目: uri65/csharp-monad
        /// <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);
        }
示例#9
0
文件: RWS.cs 项目: uri65/csharp-monad
 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));
 }