public static Try <B> Map <T, B>(this Try <T> tryValue, Func <T, B> mapper) { var failure = tryValue as Failure <T>; return(failure == null? Try.From(mapper(tryValue.Value)) : new Failure <B>(failure.Exception)); }
public static Try <B> Recover <T, B>(this Try <T> tryValue, Func <Exception, B> recovery) where B : T { if (tryValue.IsSuccess) { return(tryValue as Try <B>); } try { var failure = tryValue as Failure <T>; return(Try.From(recovery(failure.Exception))); } catch (Exception ex) { return(new Failure <B>(ex)); } }
public static Try <V> SelectMany <T, U, V>(this Try <T> tryValue, Func <T, Try <U> > selector, Func <T, U, V> resultSelector) { return(tryValue.SelectMany(x => selector(x).SelectMany(y => Try.From(resultSelector(x, y))))); }