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

Add a Collection#combinations(Closure) method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.2.0-beta-1
    • groovy-jdk
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: