Ejemplo n.º 1
0
 public static WriterResult <W, A> Tell <W, A>(A a, IEnumerable <W> ws)
 {
     if (ws == null)
     {
         throw new ArgumentNullException("ws");
     }
     return(WriterResult.Create <W, A>(a, ws));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Select
 /// </summary>
 public static Writer <W, U> Select <W, T, U>(this Writer <W, T> self, Func <T, U> select)
 {
     if (select == null)
     {
         throw new ArgumentNullException("select");
     }
     return(() =>
     {
         var resT = self();
         var resU = select(resT.Value);
         return WriterResult.Create <W, U>(resU, resT.Output);
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Select Many
        /// </summary>
        public static Writer <W, V> SelectMany <W, T, U, V>(
            this Writer <W, T> self,
            Func <T, Writer <W, U> > bind,
            Func <T, U, V> project
            )
        {
            if (bind == null)
            {
                throw new ArgumentNullException("bind");
            }
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            return(() =>
            {
                var resT = self();
                var resU = bind(resT.Value).Invoke();
                var resV = project(resT.Value, resU.Value);

                return WriterResult.Create <W, V>(resV, resT.Output.Concat(resU.Output));
            });
        }
Ejemplo n.º 4
0
 public static Writer <W, Unit> Tell <W>(W value)
 {
     return(() => WriterResult.Create <W, Unit>(Unit.Default, new W[1] {
         value
     }));
 }
Ejemplo n.º 5
0
 public static WriterResult <W, A> Tell <W, A>(A a, W w)
 {
     return(WriterResult.Create <W, A>(a, new W[1] {
         w
     }));
 }
Ejemplo n.º 6
0
 public static Writer <W, A> Return <W, A>(A a)
 {
     return(() => WriterResult.Create <W, A>(a, new W[0]));
 }