示例#1
0
 public static T ValueOrThrow <T>(this Fallible <T> source, Func <Exception, Exception> exceptionFactory)
 {
     if (source.IsSuccessful)
     {
         return(source.Value);
     }
     else
     {
         throw exceptionFactory(source.Exception);
     }
 }
示例#2
0
 public static void ToTaskCompletionSource <T>(this Fallible <T> source, TaskCompletionSource <T> tcs)
 {
     if (source.IsSuccessful)
     {
         tcs.SetResult(source.Value);
     }
     else
     {
         tcs.SetException(source.Exception);
     }
 }
示例#3
0
 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));
 }
示例#4
0
 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));
 }
示例#5
0
 public static TSource Coalesce <TSource>(this Fallible <TSource> source, Func <Exception, TSource> projection)
 {
     return(source.IsSuccessful ? source.Value : projection(source.Exception));
 }
示例#6
0
 public static T ValueOrThrow <T>(this Fallible <T> source)
 {
     return(ValueOrThrow(source, ex => ex));
 }