associateBy

inline fun <T, K, V> Iterable<T>.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V, resolve: (key: K, currentValue: V, newValue: V) -> V): Map<K, V>

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

All pairs are added in order of iteration. If some key is already added to the map, adding new key-value pair with the key is resolved with resolve function which takes the key, current value corresponding to the key, and new value from the pair.

Return

the result map.

Parameters

keySelector

lambda functions that generates keys for the key-value pairs.

valueTransform

lambda functions that generates value for the key-value pairs.

resolve

lambda function that resolves merge conflicts which receives some key, its current, and new corresponding values.


inline fun <T, K> Iterable<T>.associateBy(keySelector: (T) -> K, resolve: (key: K, currentValue: T, newValue: T) -> T): Map<K, T>

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

All pairs are added in order of iteration. If some key is already added to the map, adding new key-value pair with the key is resolved with resolve function which takes the key, current value corresponding to the key, and new value from the pair.

Return

the result map.

Parameters

keySelector

lambda functions that generates keys for the key-value pairs.

resolve

lambda function that resolves merge conflicts which receives some key, its current, and new corresponding values.