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)))); }