Copilot commented on code in PR #2750:
URL: https://github.com/apache/groovy/pull/2750#discussion_r3682395496
##########
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java:
##########
@@ -15229,6 +15604,25 @@ public static Collection split(Object self, Closure
closure) {
return split(closure, accept, reject, InvokerHelper.asIterator(self));
}
+ /**
+ * Splits all items into two collections based on the predicate.
+ * A "fat-free" variant of {@link #split(Object, Closure)} accepting a
{@link Predicate}.
+ * The first list contains all items which match the given predicate, the
second list all those that don't.
+ * <pre class="language-groovy groovyTestCase">
+ * assert [[2, 4], [1, 3]] == [1, 2, 3, 4].split(n -> n % 2 == 0)
+ * </pre>
+ *
+ * @param self an Object with an Iterator returning its values
+ * @param predicate a predicate used to determine the target collection
+ * @return a List whose first item is the accepted values and whose second
item is the rejected values
+ * @since 6.0.0
+ */
+ public static Collection split(Object self, Predicate predicate) {
Review Comment:
This overload mirrors split(Object, Closure) but currently lacks the
`@SuppressWarnings` used for the same raw/unchecked usage. With a raw Predicate
plus raw Lists, this can introduce new 'rawtypes'/'unchecked' compiler warnings
in a core runtime class.
This issue also appears in the following locations of the same file:
- line 15726
- line 15760
##########
src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java:
##########
@@ -16327,7 +16894,7 @@ private void advance() {
exhausted = !delegate.hasNext();
if (!exhausted) {
next = delegate.next();
- if (!condition.call(next)) {
+ if (!condition.test(next)) {
exhausted = true;
next = null;
}
Review Comment:
TakeWhileIterator prefetches via delegate.next() inside advance() (called
from next()). Because of that, calling remove() after next() will delegate to
the underlying iterator after an additional delegate.next() has already
happened, which can remove the wrong element. Either rework iteration to avoid
prefetching before remove, or (simplest) make remove() unsupported like other
lazy iterators here.
--
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]