public static T ValueOrThrow <T>(this Fallible <T> source, Func <Exception, Exception> exceptionFactory) { if (source.IsSuccessful) { return(source.Value); } else { throw exceptionFactory(source.Exception); } }
public static void ToTaskCompletionSource <T>(this Fallible <T> source, TaskCompletionSource <T> tcs) { if (source.IsSuccessful) { tcs.SetResult(source.Value); } else { tcs.SetException(source.Exception); } }
public static TResult Select <TSource, TResult>(this Fallible <TSource> source, Func <TSource, TResult> success, Func <Exception, TResult> fail) { return(source.IsSuccessful ? success(source.Value) : fail(source.Exception)); }
public static Fallible <TResult> Select <TSource, TResult>(this Fallible <TSource> source, Func <TSource, TResult> success) { return(source.IsSuccessful ? Fallible.Success(success(source.Value)) : Fallible.Fail <TResult>(source.Exception)); }
public static TSource Coalesce <TSource>(this Fallible <TSource> source, Func <Exception, TSource> projection) { return(source.IsSuccessful ? source.Value : projection(source.Exception)); }
public static T ValueOrThrow <T>(this Fallible <T> source) { return(ValueOrThrow(source, ex => ex)); }