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

Groovy could provide a chop DGM method

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.5.2
    • None
    • None

    Description

      The method would chop the list into pieces at a specified chop size (or chop sizes).

      assert [1, 2, 3, 4].chop(1) == [[1]]
      assert [1, 2, 3, 4].chop(1,-1) == [[1], [2, 3, 4]]
      assert ('a'..'h').chop(2, 4) == [['a', 'b'], ['c', 'd', 'e', 'f']]
      assert ['a', 'b', 'c', 'd', 'e'].chop(3) == [['a', 'b', 'c']]
      assert ['a', 'b', 'c', 'd', 'e'].chop(1, 2, 3) == [['a'], ['b', 'c'], ['d', 'e']]
      assert ['a', 'b', 'c', 'd', 'e'].chop(1, 2, 3, 3, 3) == [['a'], ['b', 'c'], ['d', 'e'], [], []]
      

      Attachments

        Activity

          People

            paulk Paul King
            paulk Paul King
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: