You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (JIRA)" <ji...@apache.org> on 2019/08/16 23:19:00 UTC

[jira] [Updated] (GROOVY-4932) groovy should provide a collectMany alias for collect{}.flatten()

     [ https://issues.apache.org/jira/browse/GROOVY-4932?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King updated GROOVY-4932:
------------------------------
    Summary: groovy should provide a collectMany alias for collect{}.flatten()  (was: groovy should provide a shorthand for: collect{}.flatten())

> groovy should provide a collectMany alias for collect{}.flatten()
> -----------------------------------------------------------------
>
>                 Key: GROOVY-4932
>                 URL: https://issues.apache.org/jira/browse/GROOVY-4932
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Minor
>             Fix For: 1.8.1
>
>
> This functionality is already available via {{Collection#sum(Closure)}} as shown here:
> {code}
> def nums = 1..10
> def squaresAndCubesOfEvens = nums.sum{ it % 2 ? [] : [it**2, it**3] }
> assert squaresAndCubesOfEvens == [4, 8, 16, 64, 36, 216, 64, 512, 100, 1000]
> {code}
> however the name {{sum}} is not intuitive in all scenarios and {{sum}} is not always the most efficient was to concatenate such lists as it directs through the Groovy '{{plus}}' operator to allow custom overriding of '{{plus}}'.
> The intention is to provide a {{collectMany}} "alias" for {{sum}} which is more efficient and has naming similar to C#'s {{Enumerable.SelectMany}} operator.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)