groupBy

inline suspend fun <E, K> ReceiveChannel<E>.groupBy(
    keySelector: (E) -> K
): Map<K, List<E>>
(source)

Platform and version requirements: JVM

Groups elements of the original channel by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.

The returned map preserves the entry iteration order of the keys produced from the original channel.

The operation is terminal. This function consumes all elements of the original ReceiveChannel.

inline suspend fun <E, K, V> ReceiveChannel<E>.groupBy(
    keySelector: (E) -> K,
    valueTransform: (E) -> V
): Map<K, List<V>>
(source)

Platform and version requirements: JVM

Groups values returned by the valueTransform function applied to each element of the original channel by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values.

The returned map preserves the entry iteration order of the keys produced from the original channel.

The operation is terminal. This function consumes all elements of the original ReceiveChannel.