public static async Task <IEnumerable <T> > CollectAsync <T>([NotNull] this IAsyncEnumerable <T> iae) { return(await iae.AggregateAsync(new List <T>(), (l, e) => { l.Add(e); return l; })); }
public static ValueTask <T> AggregateAsync <T>( this IAsyncEnumerable <IEvent> events, CancellationToken cancellationToken) where T : IAggregate, new() { return(events.AggregateAsync <T, Guid>(cancellationToken)); }
public static ValueTaskAwaiter <IReadOnlyList <T> > GetAwaiter <T>(this IAsyncEnumerable <T> asyncEnumerable) => asyncEnumerable.AggregateAsync().GetAwaiter();
/// <summary> /// Applies an accumulator function over an async sequence, returning the result of the aggregation as a single element in the result sequence. /// For aggregation behavior with incremental intermediate results. /// </summary> /// <typeparam name="TSource">The type of the elements in the source sequence and the result of the aggregation.</typeparam> /// <param name="source">An async sequence to aggregate over.</param> /// <param name="accumulator">An accumulator function to be invoked on each element.</param> /// <param name="cancellationToken">The cancelation token</param> /// <returns>An async sequence containing a single element with the final accumulator value.</returns> /// <exception cref="ArgumentNullException"><paramref name="source" /> or <paramref name="accumulator" /> is null.</exception> /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception> /// <remarks>The return type of this operator differs from the corresponding operator on IAsyncEnumerable in order to retain asynchronous behavior.</remarks> public static ValueTask <TSource> ReduceAsync <TSource>(this IAsyncEnumerable <TSource> source, Func <TSource, TSource, TSource> accumulator, CancellationToken cancellationToken) => source.AggregateAsync(accumulator, cancellationToken);
/// <summary> /// Applies an accumulator function over an async sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value, /// and the specified result selector function is used to select the result value. /// </summary> /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> /// <typeparam name="TAccumulate">The type of the accumulator value.</typeparam> /// <typeparam name="TResult">The type of the resulting value.</typeparam> /// <param name="source">An async sequence to aggregate over.</param> /// <param name="seed">The initial accumulator value.</param> /// <param name="accumulator">An accumulator function to be invoked on each element.</param> /// <param name="resultSelector">A function to transform the final accumulator value into the result value.</param> /// <param name="cancellationToken">The cancelation token</param> /// <returns>An async sequence containing a single element with the final accumulator value.</returns> /// <exception cref="ArgumentNullException"><paramref name="source" /> or <paramref name="accumulator" /> or <paramref name="resultSelector" /> is null.</exception> /// <remarks>The return type of this operator differs from the corresponding operator on IAsyncEnumerable in order to retain asynchronous behavior.</remarks> public static ValueTask <TResult> ReduceAsync <TSource, TAccumulate, TResult>(this IAsyncEnumerable <TSource> source, TAccumulate seed, Func <TAccumulate, TSource, TAccumulate> accumulator, Func <TAccumulate, TResult> resultSelector, CancellationToken cancellationToken) => source.AggregateAsync(seed, accumulator, resultSelector, cancellationToken);
/// <summary> /// Applies an accumulator function over an async sequence, returning the result of the aggregation as a single element in the result sequence. /// For aggregation behavior with incremental intermediate results. /// </summary> /// <typeparam name="TSource">The type of the elements in the source sequence and the result of the aggregation.</typeparam> /// <param name="source">An async sequence to aggregate over.</param> /// <param name="accumulator">An accumulator function to be invoked on each element.</param> /// <returns>An async sequence containing a single element with the final accumulator value.</returns> /// <exception cref="ArgumentNullException"><paramref name="source" /> or <paramref name="accumulator" /> is null.</exception> /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception> /// <remarks>The return type of this operator differs from the corresponding operator on IAsyncEnumerable in order to retain asynchronous behavior.</remarks> public static ValueTask <TSource> ReduceAsync <TSource>(this IAsyncEnumerable <TSource> source, Func <TSource, TSource, TSource> accumulator) => source.AggregateAsync(accumulator);