public static class MaybeExtensions {
public static Option<T> ToMaybe<T>(this T value) {
return Option.Return(() => value);
public static class EitherExtensions {
public static Either<L, R> ToEitherOrFailWith<L, R>(this R value, Predicate<R> predicate, L orElse) {
if (!predicate(value)) return Either.Left<L, R>(() => orElse);
return Either.Right<L, R>(() => value);
public static Either<L, R> ToEither<L, R>(this R value) {
return Either.Right<L, R>(() => value);
public static void Main()
from x in 60.ToEither<string, int>()
from y in 10.ToEitherOrFailWith(n => n > 0, "Cannot divide by Zero")
Right: r => r.ToString(),