public static IAsyncResultEnumerable <TResult, TFailure> SelectMany <TSuccess, TFailure, TBind, TResult>(this IAsyncResultEnumerable <TSuccess, TFailure> source, Func <TSuccess, Task <IEnumerable <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
                   .SelectMany(result => result
                               .Match(success =>
                                      bind
                                      .Invoke(success)
                                      .AsAsyncEnumerable()
                                      .SelectAsync(obj => resultSelector.Invoke(success, obj))
                                      .Select(Result.Success <TResult, TFailure>),
                                      failure => AsyncEnumerable.Repeat(Result.Failure <TResult, TFailure>(failure), 1)
                                      )
                               )
                   .AsAsyncResultEnumerable());
        }
        public static IAsyncOptionEnumerable <TResult> SelectMany <TSuccess, TBind, TResult>(this IAsyncOptionEnumerable <TSuccess> source, Func <TSuccess, IAsyncEnumerable <TBind> > bind, Func <TSuccess, TBind, TResult> resultSelector)
            where TSuccess : notnull
            where TResult : notnull
        {
            if (bind == null)
            {
                throw new ArgumentNullException(nameof(bind));
            }

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

            return(source
                   .SelectMany(result => result
                               .Match(success =>
                                      bind
                                      .Invoke(success)
                                      .Select(obj => resultSelector.Invoke(success, obj))
                                      .Select(Option.Some),
                                      () => AsyncEnumerable.Repeat(Option.None <TResult>(), 1)
                                      )
                               )
                   .AsAsyncOptionEnumerable());
        }
 public static IAsyncResultEnumerable <TResult, TFailure> SelectMany <TSuccess, TFailure, TBind, TResult>(this Task <Result <TSuccess, TFailure> > source, Func <TSuccess, IAsyncEnumerable <TBind> > bind, Func <TSuccess, TBind, Task <TResult> > resultSelector)
 => AsyncEnumerable.Repeat(source, 1).AsAsyncResultEnumerable().SelectMany(bind, resultSelector);
 public static IAsyncOptionEnumerable <TResult> SelectMany <TSuccess, TBind, TResult>(this Task <Option <TSuccess> > source, Func <TSuccess, IAsyncEnumerable <TBind> > bind, Func <TSuccess, TBind, TResult> resultSelector)
     where TSuccess : notnull
     where TResult : notnull
 => AsyncEnumerable.Repeat(source, 1).AsAsyncOptionEnumerable().SelectMany(bind, resultSelector);