Esempio 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));
 }
Esempio 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);
     });
 }
Esempio 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));
            });
        }
Esempio n. 4
0
 public static Writer <W, Unit> Tell <W>(W value)
 {
     return(() => WriterResult.Create <W, Unit>(Unit.Default, new W[1] {
         value
     }));
 }
Esempio 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
     }));
 }
Esempio n. 6
0
 public static Writer <W, A> Return <W, A>(A a)
 {
     return(() => WriterResult.Create <W, A>(a, new W[0]));
 }