Details
-
Type:
Improvement
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.8.2
-
Fix Version/s: None
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
Description
This would be extremely useful, much more consistent and smarter than implementations like eachWithIndex. Whenever the user provides a two parameter closure to any of those Iterable extension methods, this would mean that the first parameter is the current item and the second is its index. If the closure has one parameter (or none), the current item gets passed. In all other cases it should throw an exception. A simple and very productive convention.
This feature would be very easy to implement by checking the closure.parameterTypes.length. I know that 'cuz I have it implemented in my lib. I can provide a patch if this will help the feature to be implemented sooner.
The issue being that for maps (at least) the two parameter variants are already in use for key/value variants. There would be times for maps when you would want key/value and other times when you would want entry/index.