public static Try <C> SelectMany <A, B, C>(this Try <A> ta, Func <A, Try <B> > map, Func <A, B, C> selector) { try { if (ta.IsError) { return(ta.AsError().Value); } var a = ta.AsSuccess().Value; var tb = map(a); if (tb.IsError) { return(tb.AsError().Value); } var b = tb.AsSuccess().Value; return(selector(a, b)); } catch (Exception e) { return(e); } }
public static Result Else <A, Result>(this Try <A> either, Func <A, Result> happy, Func <Exception, Result> sad) { return(either.IsSuccess ? happy(either.AsSuccess().Value) : sad(either.AsError().Value)); }
public static Result Unify <Success, Result>(this Try <Success> either, Func <Success, Result> successFunc, Func <Exception, Result> errorFunc) { if (either.IsSuccess) { return(successFunc(either.AsSuccess().Value)); } return(errorFunc(either.AsError().Value)); }
public static Try <A> WhenError <A>(this Try <A> either, Action <Exception> callbackForError) { if (either.IsError) { callbackForError(either.AsError().Value); } return(either); }
public static Success Else <Success>(this Try <Success> either, Func <Exception, Success> callback) { if (either.IsError) { return(callback(either.AsError().Value)); } return(either.AsSuccess().Value); }
public static Try <B> SelectMany <A, B>(this Try <A> ta, Func <A, Try <B> > map) { try { if (ta.IsError) { return(ta.AsError().Value); } var a = ta.AsSuccess().Value; return(map(a)); } catch (Exception e) { return(e); } }