Пример #1
0
 public static Fallible <T> Operation <T>(Func <T> operation)
 {
     try
     {
         return(Fallible <T> .Success(operation()));
     }
     catch (Exception exception)
     {
         return(Fallible <T> .Fail(exception));
     }
 }
Пример #2
0
 public static async Task <Fallible <T> > OperationAsync <T>(Func <Task <T> > operation)
 {
     try
     {
         return(Fallible <T> .Success(await operation().ConfigureAwait(false)));
     }
     catch (Exception exception)
     {
         return(Fallible <T> .Fail(exception));
     }
 }
Пример #3
0
        public static async Task <Fallible <TResult> > SelectAsync <TSource, TResult>(this Task <Fallible <TSource> > sourceTask, Func <TSource, Task <Fallible <TResult> > > projection)
        {
            var source = await sourceTask.ConfigureAwait(false);

            return(source.IsSuccess ? await projection(source.Value).ConfigureAwait(false) : Fallible <TResult> .Fail(source.Exception));
        }
Пример #4
0
 public static async Task <Fallible <TResult> > SelectAsync <TSource, TResult>(this Fallible <TSource> source, Func <TSource, Task <TResult> > projection)
 {
     return(source.IsSuccess ? await OperationAsync(() => projection(source.Value)).ConfigureAwait(false) : Fallible <TResult> .Fail(source.Exception));
 }
Пример #5
0
 public static Fallible <TResult> Select <TSource, TResult>(this Fallible <TSource> source, Func <TSource, Fallible <TResult> > projection)
 {
     return(source.IsSuccess ? projection(source.Value) : Fallible <TResult> .Fail(source.Exception));
 }