Пример #1
0
        /// <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);
            });
        }
Пример #2
0
 public static RWSResult <W, S, A> Tell <W, S, A>(A a, IEnumerable <W> ws)
 {
     if (ws == null)
     {
         throw new ArgumentNullException("ws");
     }
     return(RWSResult.Create <W, S, A>(a, ws, default(S)));
 }
Пример #3
0
 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));
 }
Пример #4
0
 public static RWS <R, W, S, S> Get <R, W, S>(Func <S, S> f)
 {
     if (f == null)
     {
         throw new ArgumentNullException("f");
     }
     return((R r, S s) => RWSResult.Create <W, S, S>(s, new W[0], f(s)));
 }
Пример #5
0
 /// <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, Unit> Tell <R, W, S>(W value)
 {
     return((R r, S s) => RWSResult.Create <W, S, Unit>(Unit.Default, new W[1] {
         value
     }, s));
 }
Пример #7
0
 public static RWSResult <W, S, A> Tell <W, S, A>(A a, W w)
 {
     return(RWSResult.Create <W, S, A>(a, new W[1] {
         w
     }, default(S)));
 }
Пример #8
0
 public static RWS <R, W, S, A> Return <R, W, S, A>(A a)
 {
     return((R r, S s) => RWSResult.Create <W, S, A>(a, new W[0], s));
 }
Пример #9
0
 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));
 }
Пример #10
0
 public static RWS <R, W, S, Unit> Put <R, W, S>(S state)
 {
     return((R r, S s) => RWSResult.Create <W, S, Unit>(Unit.Default, new W[0], state));
 }
Пример #11
0
 public static RWS <R, W, S, S> Get <R, W, S>()
 {
     return((R r, S s) => RWSResult.Create <W, S, S>(s, new W[0], s));
 }
Пример #12
0
 public static RWS <R, W, S, R> Ask <R, W, S>()
 {
     return((R r, S s) => RWSResult.Create(r, new W[0], s));
 }