groupByTo

inline suspend fun <E, K, M : MutableMap<in K, MutableList<E>>> ReceiveChannel<E>.groupByTo(
    destination: M,
    keySelector: (E) -> K
): M
(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 puts to the destination map each group key associated with a list of corresponding elements.

Return

The destination map.

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

inline suspend fun <E, K, V, M : MutableMap<in K, MutableList<V>>> ReceiveChannel<E>.groupByTo(
    destination: M,
    keySelector: (E) -> K,
    valueTransform: (E) -> V
): M
(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 puts to the destination map each group key associated with a list of corresponding values.

Return

The destination map.

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