Shadow-Devil commented on code in PR #1785:
URL: https://github.com/apache/groovy/pull/1785#discussion_r976783483
##########
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java:
##########
@@ -2273,6 +2273,26 @@ public static <T> T[] eachWithIndex(T[] self,
@ClosureParams(value=FromString.cl
return self;
}
+ /**
+ * Iterates through an int[],
+ * passing each int and the element's index (a counter starting at
+ * zero) to the given closure.
+ * <pre class="groovyTestCase">
+ * int result = 0
+ * [0, 1, 2].eachWithIndex{ x, index {@code ->} result += x * index }
Review Comment:
I'm not sure how the debugging works, since I can't place the breakpoint
inside the javadocs and I don't think I should step through all of the test
cases.
I changed the test case to:
```
int[] nums = [5, 4, 3]
String result = ''
nums.eachWithIndex{ num, index -> result += "$index:${num + 1}" }
assert result == '0:61:52:4'
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]