public static Fallible <T> Operation <T>(Func <T> operation) { try { return(Fallible <T> .Success(operation())); } catch (Exception exception) { return(Fallible <T> .Fail(exception)); } }
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)); } }
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)); }
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)); }
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)); }