groovy
  1. groovy
  2. GROOVY-4932

groovy should provide a shorthand for: collect{}.flatten()

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      This functionality is already available via Collection#sum(Closure) as shown here:

      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]
      

      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.

        Issue Links

          Activity

          There are no comments yet on this issue.

            People

            • Assignee:
              Paul King
              Reporter:
              Paul King
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: