Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
As per the suggestion on this thread:
http://www.nabble.com/generic-%27withIndex%27-method-%28like-Ruby-1.9-with_index%29-ts25631548.html
The idea is to have access to an index or counter in all the functional methods iterating over collections, by using an additional parameter in the closure passed in parameter of those methods. That way, we don't need to add as many *withIndex variant methods to the existing ones, but rather provide a convenient convention.
Some examples with each, and similarly by replacing each with find/findAll/any/every/collect and perhaps inject:
list.each { elem -> ... }
list.each { elem, counter -> ... }
map.each { entry -> ... }
map.each { key, value -> ... }
map.each { key, value, counter -> ... }
Issue Links
- duplicates
-
GROOVY-1182
align 2-arg 'each' methods on Maps and Lists and else; remove eachWithIndex
-
- is related to
-
GROOVY-2838
Add everyWithIndex, anyWithIndex, collectWithIndex, sumWithIndex ... or add indexGen
-
-
GROOVY-1182
align 2-arg 'each' methods on Maps and Lists and else; remove eachWithIndex
-
The only isue I can see being potentially problematic here is that in:
def flob ( adob ) { adob.each { x , y -> . . . } }will lead to new behaviour compared to previously.