Method AggregateBy
View SourceAggregateBy<TSource, TKey, TAccumulate>(IAsyncEnumerable<TSource>, Func<TSource, TKey>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, IEqualityComparer<TKey>?)
Applies a key-generating function to each element of a sequence and returns an aggregate value for each key. An additional argument specifies a comparer to use for testing equivalence of keys.
Declaration
public static IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> AggregateBy<TSource, TKey, TAccumulate>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, IEqualityComparer<TKey>? comparer = null) where TKey : notnull
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | Source sequence. |
Func<TSource, TKey> | keySelector | Function that transforms each item of source sequence into a key to be compared against the others. |
TAccumulate | seed | The initial accumulator value for each key-group. |
Func<TAccumulate, TSource, TAccumulate> | func | An accumulator function to be invoked on each element. The accumulator value is tracked separately for each key. |
IEqualityComparer<TKey> | comparer | The equality comparer to use to determine whether or not keys are equal. If null, the
default equality comparer for |
Returns
Type | Description |
---|---|
IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> | A sequence of unique keys and their accumulated value. |
Type Parameters
Name | Description |
---|---|
TSource | Type of the elements of the source sequence. |
TKey | Type of the projected element. |
TAccumulate | Type of the accumulator value. |
Remarks
This method is implemented by using deferred execution. The operator will be executed in it's entirety immediately when the sequence is first enumerated.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
AggregateBy<TSource, TKey, TAccumulate>(IAsyncEnumerable<TSource>, Func<TSource, TKey>, Func<TKey, TAccumulate>, Func<TAccumulate, TSource, TAccumulate>, IEqualityComparer<TKey>?)
Applies a key-generating function to each element of a sequence and returns an aggregate value for each key. An additional argument specifies a comparer to use for testing equivalence of keys.
Declaration
public static IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> AggregateBy<TSource, TKey, TAccumulate>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, TAccumulate> seedSelector, Func<TAccumulate, TSource, TAccumulate> func, IEqualityComparer<TKey>? comparer = null) where TKey : notnull
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | Source sequence. |
Func<TSource, TKey> | keySelector | Function that transforms each item of source sequence into a key to be compared against the others. |
Func<TKey, TAccumulate> | seedSelector | A function that returns the initial seed for each key. |
Func<TAccumulate, TSource, TAccumulate> | func | An accumulator function to be invoked on each element. The accumulator value is tracked separately for each key. |
IEqualityComparer<TKey> | comparer | The equality comparer to use to determine whether or not keys are equal. If null, the
default equality comparer for |
Returns
Type | Description |
---|---|
IAsyncEnumerable<KeyValuePair<TKey, TAccumulate>> | A sequence of unique keys and their accumulated value. |
Type Parameters
Name | Description |
---|---|
TSource | Type of the elements of the source sequence. |
TKey | Type of the projected element. |
TAccumulate | Type of the accumulator value. |
Remarks
This method is implemented by using deferred execution. The operator will be executed in it's entirety immediately when the sequence is first enumerated.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|