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

Groovy could benefit from DGM takeWhile and dropWhile methods

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.8.6
    • 2.0-beta-3, 1.8.7
    • groovy-jdk
    • None

    Description

      Currently, there is a take method on collections that returns the first N items in a collection. Other languages such as scala and haskell also provide a takeWhile method, that is similar. Instead of taking a fixed number of items, it takes items until a condition, in the form of a closure, is met.

      For example:

      def items = [1,2,3,4,5,4,3,2,1]
      def sublist = items.takeWhile { it < 5 }
      assert sublist == [1,2,3,4]
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: