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 <TResult> > projection) { var source = await sourceTask.ConfigureAwait(false); return(source.IsSuccess ? Fallible <TResult> .Success(await projection(source.Value).ConfigureAwait(false)) : Fallible <TResult> .Fail(source.Exception)); }