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

Add a collate method to List

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.8.5
    • 1.8.6, 2.0-beta-3
    • None
    • None

    Description

      I have often found a need for collating or partitioning a List into a List of sub-lists of a given size.

      This question has been asked on StackOverflow a couple of times as well

      ie:

      [1,2,3,4,5].collate( 3 ) == [ [ 1, 2, 3 ], [ 4, 5 ] ]
      

      This could be chained to generate a multi-dimensional list of lists, ie:

      (1..9).collate( 3 ).collate( 2 ) == [ [ [1,2,3], [4,5,6] ],
                                            [ [7,8,9]          ] ]
      

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            tim_yates Tim Yates
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: