AsyncLinqExtensions.

ReduceAsync<TSource>(IAsyncEnumerable<TSource>, Func<TSource, TSource, TSource>, CancellationToken) Method

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.

Syntax

public static ValueTask<TSource> ReduceAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator, CancellationToken cancellationToken)

Remarks

The return type of this operator differs from the corresponding operator on IAsyncEnumerable in order to retain asynchronous behavior.

Type Parameters

Name Description
TSource The type of the elements in the source sequence and the result of the aggregation.

Parameters

Name Type Description
source IAsyncEnumerable<TSource> An async sequence to aggregate over.
accumulator Func<TSource, TSource, TSource> An accumulator function to be invoked on each element.
cancellationToken CancellationToken The cancelation token

Return Value

Type Description
ValueTask<TSource> An async sequence containing a single element with the final accumulator value.