Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6057

Add a Collection#combinations(Closure) method

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2.0-beta-1
    • Component/s: groovy-jdk
    • Labels:
      None

      Description

      The combinations method is very useful, but in practice, it's rare that you want to limit yourself to the list of generated combinations. Often, you want to apply an action on each combination.

      I suggest to add the following variant:

      assert [[2, 3],[4, 5, 6]].combinations {x,y -> x*y } == [8, 12, 10, 15, 12, 18]
      

      which avoids the working but less elegant code:

      assert [[2, 3],[4, 5, 6]].combinations().collect {x,y -> x*y } == [8, 12, 10, 15, 12, 18]
      

        Attachments

          Activity

            People

            • Assignee:
              melix Cédric Champeau
              Reporter:
              melix Cédric Champeau
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: