Kotlin HashSet groupBy()
Syntax & Examples


Syntax of HashSet.groupBy()

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

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

This extension function groups elements of the original collection by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.

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

This extension function groups values returned by the valueTransform function applied to each element of the original collection by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values.