You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/05/12 06:11:00 UTC
[jira] [Updated] (GROOVY-7350) findAll and findResults should take
an optional 'collector' argument
[ https://issues.apache.org/jira/browse/GROOVY-7350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Shil Sinha updated GROOVY-7350:
-------------------------------
Component/s: (was: groovy-jdk)
groovy-runtime
> findAll and findResults should take an optional 'collector' argument
> --------------------------------------------------------------------
>
> Key: GROOVY-7350
> URL: https://issues.apache.org/jira/browse/GROOVY-7350
> Project: Groovy
> Issue Type: Improvement
> Components: groovy-runtime
> Reporter: Shil Sinha
> Assignee: Guillaume Delcroix
>
> 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:
> {code}
> 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 }
> {code}
> 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)}}.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)