associateBy

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

Platform and version requirements: JVM

Returns a Map containing the elements from the given channel indexed by the key returned from keySelector function applied to each element.

If any two elements would have the same key returned by keySelector the last one gets added to the map.

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

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

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

Platform and version requirements: JVM

Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given channel.

If any two elements would have the same key returned by keySelector the last one gets added to the map.

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

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