Exemplo n.º 1
0
        public static async Task <Fallible <T> > OnFailureAsync <T>(this Fallible <T> source, Func <Exception, Task> action)
        {
            if (source.IsFailure)
            {
                await action(source.Exception).ConfigureAwait(false);
            }

            return(source);
        }
Exemplo n.º 2
0
        public static Fallible <T> OnSuccess <T>(this Fallible <T> source, Action <T> action)
        {
            if (source.IsSuccess)
            {
                action(source.Value);
            }

            return(source);
        }
Exemplo n.º 3
0
        public static Fallible <T> OnFailure <T>(this Fallible <T> source, Action <Exception> action)
        {
            if (source.IsFailure)
            {
                action(source.Exception);
            }

            return(source);
        }
Exemplo n.º 4
0
        public static async Task <Fallible <T> > OnSuccessAsync <T>(this Fallible <T> source, Func <T, Task> action)
        {
            if (source.IsSuccess)
            {
                await action(source.Value).ConfigureAwait(false);
            }

            return(source);
        }
Exemplo n.º 5
0
 public static Fallible <T> Operation <T>(Func <T> operation)
 {
     try
     {
         return(Fallible <T> .Success(operation()));
     }
     catch (Exception exception)
     {
         return(Fallible <T> .Fail(exception));
     }
 }
Exemplo n.º 6
0
 public static void Do <T>(this Fallible <T> source, Action <T> onSuccess, Action <Exception> onFail)
 {
     if (source.IsSuccess)
     {
         onSuccess(source.Value);
     }
     else
     {
         onFail(source.Exception);
     }
 }
Exemplo n.º 7
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));
     }
 }
Exemplo n.º 8
0
 public static T ValueOrThrow <T>(this Fallible <T> source)
 {
     if (source.IsSuccess)
     {
         return(source.Value);
     }
     else
     {
         throw source.Exception;
     }
 }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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));
 }
Exemplo n.º 11
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));
 }
Exemplo n.º 12
0
 public static Fallible <TDest> Cast <TSource, TDest>(this Fallible <TSource> source) where TDest : TSource
 {
     return(source.Select(value => Operation(() => (TDest)value)));
 }
Exemplo n.º 13
0
 public static Fallible <T> Coalesce <T>(this Fallible <T> source, Func <Exception, Fallible <T> > projection)
 {
     return(source.IsSuccess ? source : projection(source.Exception));
 }