assocBy

inline fun <T, K> Iterable<T>.assocBy(keySelector: (T) -> K): Map<K, T>
inline fun <T, K> Sequence<T>.assocBy(keySelector: (T) -> K): 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.

If any two elements had the same key returned by keySelector the last one gets added to the map and the method creates a warning.

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

inline fun <T, K, V> Iterable<T>.assocBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map<K, V>
inline fun <T, K, V> Sequence<T>.assocBy(keySelector: (T) -> K, valueTransform: (T) -> 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.

If any two elements had the same key returned by keySelector the last one gets added to the map and the method creates a warning.

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