Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
Currently, the only DGM methods that support providing a collection with which to collect results are collect, collectNested, collectEntries, and collectMany.
Without this ability for findAll and findResults, one has to convert the resulting collection to the desired type after the fact, which results in extra collections being created.
Example:
def list = [1, 2, 2, 6, 7, 9] // we want to get the set of unique even numbers in the list // creates new list and set def oldAnswer = list.findAll { it % 2 == 0 }.toSet() // only uses the given set def newAnswer = list.findAll(new HashSet()) { it % 2 == 0 }
I have created a pull request with the necessary changes here: https://github.com/groovy/groovy-core/pull/643
The implementation is essentially the same as that of collect(collection, collector, closure).
Attachments
Issue Links
- relates to
-
GROOVY-10891 We should have variants of findResult/s with no Closure which use Closure.IDENTITY in that case
- Closed