public static Try <O> Map <T, O>(this Try <T> @try, Func <T, O> func) { if (func == null) { throw new ArgumentNullException(nameof(func)); } Try <O> f = () => @try.Run().Match(t => Exceptional <O> .Return(func(t)), exception => Exceptional <O> .Return(exception)); return(f); }
public static Exceptional <T> Run <T>(this Try <T> @try) { try { return(@try()); } catch (Exception e) { return(Exceptional <T> .Return(e)); } }
public static O Match <T, O>(this Exceptional <T> exceptional, Func <T, O> func, Func <Exception, O> exception) { if (func == null) { throw new ArgumentNullException(nameof(func)); } if (exception == null) { throw new ArgumentNullException(nameof(exception)); } if (!exceptional.HasException) { return(func(exceptional.Value)); } else { return(exception(exceptional.Exception)); } }
public static Try <T> AsTry <T>(this Func <T> func) { return(() => Exceptional <T> .Return(func())); }