public static IAsyncOptionEnumerable <TResult> SelectMany <TSuccess, TBind, TResult>(this IAsyncOptionEnumerable <TSuccess> source, Func <TSuccess, Task <Option <TBind> > > bind, Func <TSuccess, TBind, TResult> resultSelector) where TSuccess : 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 .SelectAsync(result => result .MatchAsync(success => bind .Invoke(success) .Map(value => resultSelector.Invoke(success, value)), () => Task.FromResult(Option.None <TResult>()) ) ) .AsAsyncOptionEnumerable()); }
public static IAsyncOptionEnumerable <TValue> Where <TValue>(this IAsyncOptionEnumerable <TValue> source, Func <TValue, Task <Option <Unit> > > failurePredicate) => source .SelectAsync(value => value .BindAsync(success => failurePredicate .Invoke(success) .Map(_ => success) ) ) .AsAsyncOptionEnumerable();
public static IAsyncOptionEnumerable <TResult> Select <TSuccess, TResult>(this IAsyncOptionEnumerable <TSuccess> source, Func <TSuccess, Task <TResult> > selector) { if (selector == null) { throw new ArgumentNullException(nameof(selector)); } return(source .SelectAsync(result => result .MatchAsync( success => Option.SomeAsync(selector.Invoke(success)), () => Task.FromResult(Option.None <TResult>()) ) ) .AsAsyncOptionEnumerable()); }