public static IAsyncResultEnumerable <TResult, TFailure> SelectMany <TSuccess, TFailure, TBind, TResult>(this IAsyncResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <TBind, TFailure> > bind, Func <TSuccess, TBind, TResult> resultSelector)
            where TSuccess : notnull
            where TFailure : notnull
            where TBind : notnull
            where TResult : notnull
        {
            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)
                                  .Map(value => resultSelector.Invoke(success, value)),
                                  Result.Failure <TResult, TFailure>
                                  )
                           )
                   .AsAsyncResultEnumerable());
        }
 public static IAsyncResultEnumerable <TSuccess, TFailure> Where <TSuccess, TFailure>(this IAsyncResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Result <Unit, TFailure> > failurePredicate)
 => source
 .Select(value => value
         .Bind(success => failurePredicate
               .Invoke(success)
               .Select(_ => success)
               )
         )
 .AsAsyncResultEnumerable();
Example #3
0
        public static IAsyncResultEnumerable <TResult, TFailure> Select <TSuccess, TResult, TFailure>(this IAsyncResultEnumerable <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>
                               )
                           )
                   .AsAsyncResultEnumerable());
        }