Kotlin HashSet groupByTo()
Syntax & Examples
Syntax of HashSet.groupByTo()
There are 2 variations for the syntax of HashSet.groupByTo() extension function. They are:
1.
fun <T, K, M : MutableMap<in K, MutableList<T>>> Iterable<T>.groupByTo( destination: M, keySelector: (T) -> K ): M
This extension function groups elements of the original collection by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.
2.
fun <T, K, V, M : MutableMap<in K, MutableList<V>>> Iterable<T>.groupByTo( destination: M, keySelector: (T) -> K, valueTransform: (T) -> V ): M
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 puts to the destination map each group key associated with a list of corresponding values.