Problem Statement
Which function would you use to group collection elements by a key?
Explanation
The groupBy function groups elements by a key selector function returning a Map where keys are the results of the selector and values are lists of elements with that key, like people dot groupBy open curly it dot age close curly groups people by age. It's perfect for categorizing data based on properties.
Related functions include partition which splits a collection into two lists based on a predicate, associate which creates a Map from elements with custom key-value pairs, and groupingBy for more advanced grouping with aggregation operations.
GroupBy is commonly used for data analysis, creating lookup tables, or organizing data by categories, and it handles duplicate keys automatically by collecting all matching elements into lists.
Practice Sets
This question appears in the following practice sets: