Exemple #1
0
        private static void PlayAroundEitherMonad()
        {
            var exec1 = from x in 0.ToExceptional()
                        from y in Exceptional.Execute(() => 6 / x)
                        from z in 7.ToExceptional()
                        select x + y + z;

            Console.WriteLine("Exceptional Result 1: " + exec1);

            var exec2 = Exceptional.From(0)
                        .ThenExecute(x => x + 6 / x)
                        .ThenExecute(y => y + 7);

            Console.WriteLine("Exceptional Result 2: " + exec2);

            var exec3 = Exceptional.From(3)
                        .ThenExecute(x => x + 6 / x)
                        .ThenExecute(y => y + 7);

            Console.WriteLine("Exceptional Result 3: " + exec3);
        }
 public static Exceptional <U> ThenExecute <T, U>(this Exceptional <T> value, Func <T, U> getValue)
 {
     return(value.SelectMany(x => Exceptional.Execute(() => getValue(x))));
 }
 public static Exceptional <V> SelectMany <T, U, V>(this Exceptional <T> value, Func <T, Exceptional <U> > k, Func <T, U, V> m)
 {
     return(value.SelectMany(t => k(t).SelectMany(u => m(t, u).ToExceptional())));
 }
 public static Exceptional <U> SelectMany <T, U>(this Exceptional <T> value, Func <T, Exceptional <U> > k)
 {
     return((value.HasException)
         ? new Exceptional <U>(value.Exception)
         : k(value.Value));
 }