コード例 #1
0
        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()));
        }
コード例 #2
0
 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();
コード例 #3
0
 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();
コード例 #4
0
 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);
コード例 #5
0
 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);
コード例 #7
0
 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>()))));