English | 简体中文

api-docs / org.ktorm.entity / associateBy

associateBy

inline fun <E : Any, K> EntitySequence<E, *>.associateBy(
    keySelector: (E) -> K
): Map<K, E>
(source code)

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

If any two elements 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 sequence.

The operation is terminal.

inline fun <E : Any, K, V> EntitySequence<E, *>.associateBy(
    keySelector: (E) -> K,
    valueTransform: (E) -> V
): Map<K, V>
(source code)

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

If any two elements 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 sequence.

The operation is terminal.