AsyncEnumerable.CountBy Method

Definition

Overloads

CountBy<TSource,TKey>(IAsyncEnumerable<TSource>, Func<TSource,CancellationToken,ValueTask<TKey>>, IEqualityComparer<TKey>)

Source:
CountBy.cs

Returns the count of elements in the source sequence grouped by key.

C#
public static System.Collections.Generic.IAsyncEnumerable<System.Collections.Generic.KeyValuePair<TKey,int>> CountBy<TSource,TKey>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,System.Threading.CancellationToken,System.Threading.Tasks.ValueTask<TKey>> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer = default);

Type Parameters

TSource

The type of elements of source.

TKey

The type of the key returned by keySelector.

Parameters

source
IAsyncEnumerable<TSource>

A sequence that contains elements to be counted.

keySelector
Func<TSource,CancellationToken,ValueTask<TKey>>

A function to extract the key for each element.

keyComparer
IEqualityComparer<TKey>

An IEqualityComparer<T> to compare keys with.

Returns

An enumerable containing the frequencies of each key occurrence in source.

Exceptions

keySelector is null.

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)

CountBy<TSource,TKey>(IAsyncEnumerable<TSource>, Func<TSource,TKey>, IEqualityComparer<TKey>)

Source:
CountBy.cs

Returns the count of elements in the source sequence grouped by key.

C#
public static System.Collections.Generic.IAsyncEnumerable<System.Collections.Generic.KeyValuePair<TKey,int>> CountBy<TSource,TKey>(this System.Collections.Generic.IAsyncEnumerable<TSource> source, Func<TSource,TKey> keySelector, System.Collections.Generic.IEqualityComparer<TKey>? keyComparer = default);

Type Parameters

TSource

The type of elements of source.

TKey

The type of the key returned by keySelector.

Parameters

source
IAsyncEnumerable<TSource>

A sequence that contains elements to be counted.

keySelector
Func<TSource,TKey>

A function to extract the key for each element.

keyComparer
IEqualityComparer<TKey>

An IEqualityComparer<T> to compare keys with.

Returns

An enumerable containing the frequencies of each key occurrence in source.

Exceptions

keySelector is null.

Applies to

.NET 10 and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided), 10
.NET Standard 2.0 (package-provided)