public static IAsyncResultEnumerable <TResult, TFailure> SelectMany <TSuccess, TFailure, TBind, TResult>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, IAsyncEnumerable <TBind> > bind, Func <TSuccess, TBind, Task <TResult> > resultSelector)
        {
            if (bind == null)
            {
                throw new ArgumentNullException(nameof(bind));
            }

            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return(source
                   .AsAsyncEnumerable()
                   .SelectMany(result => result
                               .Match(success =>
                                      bind
                                      .Invoke(success)
                                      .SelectAsync(obj => resultSelector.Invoke(success, obj))
                                      .Select(Result.Success <TResult, TFailure>),
                                      failure => AsyncEnumerable.Repeat(Result.Failure <TResult, TFailure>(failure), 1)
                                      )
                               )
                   .AsAsyncResultEnumerable());
        }
        public static IAsyncResultEnumerable <TResult, TFailure> SelectMany <TSuccess, TFailure, TBind, TResult>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Task <Result <TBind, TFailure> > > bind, Func <TSuccess, TBind, Task <TResult> > resultSelector)
        {
            if (bind == null)
            {
                throw new ArgumentNullException(nameof(bind));
            }

            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return(source
                   .AsAsyncEnumerable()
                   .SelectAsync(result => result
                                .MatchAsync(success =>
                                            bind
                                            .Invoke(success)
                                            .SelectAsync(value => resultSelector.Invoke(success, value)),
                                            failure => Task.FromResult(Result.Failure <TResult, TFailure>(failure))
                                            )
                                )
                   .AsAsyncResultEnumerable());
        }
Example #3
0
 public static IResultEnumerable <TSuccess, TFailure> Where <TSuccess, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <Unit, TFailure> > failurePredicate)
     where TSuccess : notnull
     where TFailure : notnull
 => source
 .Select((Func <Result <TSuccess, TFailure>, Result <TSuccess, TFailure> >)(value => value
                                                                            .Bind((Func <TSuccess, Result <TSuccess, TFailure> >)(success => (Result <TSuccess, TFailure>)ResultExtensions.Map <Unit, TFailure, TSuccess>(failurePredicate
                                                                                                                                                                                                                          .Invoke((TSuccess)success)
                                                                                                                                                                                                                          , (Func <Unit, TSuccess>)(_ => (TSuccess)success)))
                                                                                  ))
         )
 .AsResultEnumerable();
Example #4
0
 public static IAsyncResultEnumerable <TSuccess, TFailure> Where <TSuccess, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Task <Result <Unit, TFailure> > > failurePredicate)
     where TSuccess : notnull
     where TFailure : notnull
 => source
 .SelectAsync(value => value
              .BindAsync(success => failurePredicate
                         .Invoke(success)
                         .Map(_ => success)
                         )
              )
 .AsAsyncResultEnumerable();
Example #5
0
        public static IResultEnumerable <TResult, TFailure> Select <TSuccess, TResult, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, TResult> selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            return(source
                   .Select(result => result
                           .Match(
                               success => Result.Success <TResult, TFailure>(selector.Invoke(success)),
                               Result.Failure <TResult, TFailure>
                               )
                           )
                   .AsResultEnumerable());
        }
 public static IResultEnumerable <TSuccess, TFailure> Where <TSuccess, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <Unit, TFailure> > failurePredicate)
 => source
 .Select(value => value
         .Bind(success => failurePredicate
               .Invoke(success)
               .Select(_ => success)
               )
         )
 .AsResultEnumerable();
Example #7
0
        public static IResultEnumerable <TResult, TFailure> SelectMany <TSuccess, TFailure, TBind, TResult>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <TBind, TFailure> > bind, Func <TSuccess, TBind, TResult> resultSelector)
        {
            if (bind == null)
            {
                throw new ArgumentNullException(nameof(bind));
            }

            if (resultSelector == null)
            {
                throw new ArgumentNullException(nameof(resultSelector));
            }

            return(source
                   .Select(result => result
                           .Match(success =>
                                  bind
                                  .Invoke(success)
                                  .Select(value => resultSelector.Invoke(success, value)),
                                  Result.Failure <TResult, TFailure>
                                  )
                           )
                   .AsResultEnumerable());
        }
        public static IAsyncResultEnumerable <TResult, TFailure> Select <TSuccess, TResult, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Task <TResult> > selector)
            where TSuccess : notnull
            where TFailure : notnull
            where TResult : notnull
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            return(source
                   .SelectAsync(result => result
                                .MatchAsync(
                                    success => Result.SuccessAsync <TResult, TFailure>(selector.Invoke(success)),
                                    failure => Task.FromResult(Result.Failure <TResult, TFailure>(failure))
                                    )
                                )
                   .AsAsyncResultEnumerable());
        }
Example #9
0
 public ResultGroupByEnumerable(IResultEnumerable <TSuccess, TFailure> successEnumerable, Func <TSuccess, TKey> keySelector, Func <TSuccess, TElement> elementSelector)
 {
     _successEnumerable = successEnumerable;
     _keySelector       = keySelector;
     _elementSelector   = elementSelector;
 }
Example #10
0
 public static IResultEnumerable <IGrouping <TKey, TElement>, TFailure> GroupBy <TKey, TSuccess, TElement, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, TKey> keySelector, Func <TSuccess, TElement> elementSelector)
 => new ResultGroupByEnumerable <TKey, TSuccess, TElement, TFailure>(source, keySelector, elementSelector);
Example #11
0
 public static IResultEnumerable <IGrouping <TKey, TSuccess>, TFailure> GroupBy <TKey, TSuccess, TFailure>(this IResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, TKey> keySelector)
     where TSuccess : notnull
     where TFailure : notnull
 => new ResultGroupByEnumerable <TKey, TSuccess, TSuccess, TFailure>(source, keySelector, _ => _);