Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.8.6
-
Fix Version/s: 2.0-beta-3, 1.8.7
-
Component/s: groovy-jdk
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
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]
Issue Links
- is related to
-
GROOVY-4865
Add a take method to Collections, Iterators, Arrays
-
Pull request on github:
https://github.com/groovy/groovy-core/pull/44