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

Add a take method to Collections, Iterators, Arrays

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.8.1, 1.9-beta-1
    • groovy-jdk
    • None

    Description

      With regards to a thread in the groovy user list here:

      http://groovy.329449.n5.nabble.com/How-to-access-first-10-characters-even-if-string-only-have-5-td4456146.html

      A take( n ) method would be a really useful addition to the Groovy codebase

      It is assumed it will work similar to other languages, in that:

      def a = [ 1, 2, 3 ]
      
      assert a.take( 0 ) == []
      assert a.take( 1 ) == [ 1 ]
      assert a.take( 4 ) == [ 1, 2, 3 ]
      

      The method should work for Collection, String, Map and lazily for Iterator, Reader and InputStream

      Attachments

        1. eighth_iteration.diff
          19 kB
          Tim Yates

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: