Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Duplicate
-
Affects Version/s: 1.0-JSR-4
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
Description
Map.each reacts differently according to whether one or two args are passed into the closure.
The same approach can be taken for ease of use and consistency for Lists and else.
['a','b'].each
{println it}['a','b'].each
{item, count -> println "$count: $item"}eachWithIndex can be dropped then. (or at least be marked 'deprecated')
we need to go over all usage of eachWithIndex, e.g. in general 'object iteration methods', GPathResult, etc.
Issue Links
- is duplicated by
-
GROOVY-3797
Provide an index or counter for each/find/findAll/collect and friends by taking into accounts the arity of closures passed to them
-
- relates to
-
GROOVY-3797
Provide an index or counter for each/find/findAll/collect and friends by taking into accounts the arity of closures passed to them
-
But eachWithIndex is defined on Maps and is quite useful:
m = [hello: "world"]
{x, i -> println x.key}m.eachWithIndex
prints hello
I'd rather see
m.eachWithIndex
{k, v, i -> println v}be implemented