public static async Task <Result <TValue, TFailure> > ToResultAsync <TValue, TFailure>(this Option <TValue> option, Func <Task <TFailure> > failureFactory)
            where TValue : notnull
            where TFailure : notnull
        {
            if (failureFactory == null)
            {
                throw new ArgumentNullException(nameof(failureFactory));
            }

            if (option.TryGetValue(out var some))
            {
                return(Result.Success <TValue, TFailure>(some));
            }

            return(Result.Failure <TValue, TFailure>(await failureFactory.Invoke()));
        }
 public static async Task <Option <TValue> > BindOnNoneAsync <TValue>(this Option <TValue> option, Func <Task <Option <TValue> > > bind)
     where TValue : notnull
 => option.TryGetValue(out _) ? option : await bind();
 public static async Task <TValue> ValueOrDefaultAsync <TValue>(this Option <TValue> option, Func <Task <TValue> > valueFactory)
     where TValue : notnull
 => option.TryGetValue(out var some) ? some : await valueFactory.Invoke();
 public static async Task <Option <TValue> > DoOnNoneAsync <TValue>(this Option <TValue> option, Func <Task> @do)
     where TValue : notnull
 => await option.DoAsync(DelegateCache <TValue> .Task, @do);
 public static Task ApplyAsync <TValue>(this Option <TValue> option, Func <TValue, Task> applyWhenSome, Func <Task> applyWhenNone)
     where TValue : notnull
 => option.DoAsync(applyWhenSome, applyWhenNone);
示例#6
0
 public static Task <Option <TFailure> > Failure <TSuccess, TFailure>(this Task <Result <TSuccess, TFailure> > result)
 => result.Match(_ => Option.None <TFailure>(), Option.Some);
 public static Task <Option <TValue> > DoAsync <TValue>(this Option <TValue> option, Func <TValue, Task> @do)
     where TValue : notnull
 => option.DoAsync(@do, DelegateCache.Task);
示例#8
0
 public static Task <Option <TSuccess> > Success <TSuccess, TFailure>(this Task <Result <TSuccess, TFailure> > result)
 => result.Match(Option.Some, _ => Option.None <TSuccess>());
示例#9
0
 public static Option <TSuccess> ToOption <TSuccess, TFailure>(this Result <TSuccess, TFailure> result)
 => result.Match(Option.Some, _ => Option.None <TSuccess>());
示例#10
0
 public static Task <Result <Option <TResult>, TFailure> > BindIfSomeAsync <TSuccess, TFailure, TResult>(this Result <Option <TSuccess>, TFailure> result, Func <TSuccess, Task <Result <Option <TResult>, TFailure> > > bind)
 => result.BindAsync(success => success.MatchAsync(bind, () => Task.FromResult(Result.Success <Option <TResult>, TFailure>(Option.None <TResult>()))));
示例#11
0
 public static Result <Option <TResult>, TFailure> BindIfSome <TSuccess, TFailure, TResult>(this Result <Option <TSuccess>, TFailure> result, Func <TSuccess, Result <Option <TResult>, TFailure> > bind)
 => result.Bind(success => success.Match(bind, () => Result.Success <Option <TResult>, TFailure>(Option.None <TResult>())));
示例#12
0
 public static Task <Result <Option <TResult>, TFailure> > BindIfSomeAsync <TSuccess, TFailure, TResult>(this Result <Option <TSuccess>, TFailure> result, Func <TSuccess, Task <Result <TResult, TFailure> > > bind)
 => result.BindAsync(success => success.MatchAsync(async value => (await bind(value)).Select(Option.Some), () => Task.FromResult(Result.Success <Option <TResult>, TFailure>(Option.None <TResult>()))));