Kotlin HashSet associateBy()
Syntax & Examples


Syntax of HashSet.associateBy()

There are 2 variations for the syntax of HashSet.associateBy() extension function. They are:

1.
fun <T, K> Iterable<T>.associateBy( keySelector: (T) -> K ): Map<K, T>

This extension function returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element.

2.
fun <T, K, V> Iterable<T>.associateBy( keySelector: (T) -> K, valueTransform: (T) -> V ): Map<K, V>

This extension function returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given collection.