Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0
-
None
-
None
Description
The documentation for Collection.groupBy is a little ambiguous in that it does not make it absolutely clear that the return value is a Map of keys pointing to values that are ArrayLists.
A new method, Collection.collate(Closure) would be a nice addition, to allow collation of a collection of objects into a map keyed on some value provided by a closure, without returning a List for every value. This might be implemented so:
java.util.Map collate(Closure collator) {
def result = [:]
this.each() {
result[collator.call(it)] = it
}
}