Skip to content

Commit 484e903

Browse files
committed
GROOVY-11596, GROOVY-11351: Minor refactor: Improve consistency for DGM Iterator/Iterable variant combinations
1 parent af5a1b5 commit 484e903

File tree

1 file changed

+2
-61
lines changed

1 file changed

+2
-61
lines changed

src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java

+2-61
Original file line numberDiff line numberDiff line change
@@ -1947,7 +1947,8 @@ public static <T> Iterator<List<T>> chop(Iterator<T> self, Iterator<Integer> cho
19471947
* <p>
19481948
* Example usage:
19491949
* <pre class="groovyTestCase">
1950-
* def shape = Iterators.iterate(1, n {@code ->} n + 2).take(10).plus([3] * 3)
1950+
* def trunk = [3, 3, 3].iterator()
1951+
* def shape = Iterators.iterate(1, n {@code ->} n + 2).take(10).plus(trunk)
19511952
* def tree = ['*']
19521953
* .repeat()
19531954
* .chop(true, shape)
@@ -11134,22 +11135,6 @@ public static <T> Iterator<T> plus(Iterator<T> left, Iterator<T> right) {
1113411135
return new PlusIterator<>(left, right);
1113511136
}
1113611137

11137-
/**
11138-
* Appends an iterator and an iterable.
11139-
*
11140-
* <pre class="groovyTestCase">
11141-
* assert [1, 2].iterator().plus([3, 4]).toList() == 1..4
11142-
* </pre>
11143-
*
11144-
* @param left an Iterator
11145-
* @param right an Iterable
11146-
* @return an iterator of all the items from first then second
11147-
* @since 5.0.0
11148-
*/
11149-
public static <T> Iterator<T> plus(Iterator<T> left, Iterable<T> right) {
11150-
return plus(left, right.iterator());
11151-
}
11152-
1115311138
private static final class PlusIterator<E> implements Iterator<E> {
1115411139
private final Iterator<E> first;
1115511140
private final Iterator<E> second;
@@ -17100,27 +17085,6 @@ public static <U, V> Iterator<Tuple2<U, V>> zip(Iterator<U> self, Iterator<V> ot
1710017085
return new ZipIterator<>(self, other);
1710117086
}
1710217087

17103-
/**
17104-
* An iterator of all the pairs from this iterator and the iterable.
17105-
* If the sources are of different sizes, the result will have the same
17106-
* size as the shorter one.
17107-
* <p>
17108-
* Example:
17109-
* <pre class="groovyTestCase">
17110-
* def small = [1, 2, 3].iterator()
17111-
* def large = [100, 200, 300]
17112-
* assert [101, 202, 303] == small.zip(large).collect{ a, b {@code ->} a + b }
17113-
* </pre>
17114-
*
17115-
* @param self an Iterator
17116-
* @param other an Iterable
17117-
* @return an iterator of all the pairs from self and other
17118-
* @since 5.0.0
17119-
*/
17120-
public static <U, V> Iterator<Tuple2<U, V>> zip(Iterator<U> self, Iterable<V> other) {
17121-
return zip(self, other.iterator());
17122-
}
17123-
1712417088
private static final class ZipIterator<U, V> implements Iterator<Tuple2<U, V>> {
1712517089
private final Iterator<U> delegate;
1712617090
private final Iterator<V> other;
@@ -17199,29 +17163,6 @@ public static <U, V> Iterator<Tuple2<U, V>> zipAll(Iterator<U> left, Iterator<V>
1719917163
return new ZipAllIterator<>(left, right, leftDefault, rightDefault);
1720017164
}
1720117165

17202-
/**
17203-
* An iterator of all the pairs of an Iterator and an Iterable with potentially different numbers of elements.
17204-
* If the iterables are of different sizes, the result will have the same
17205-
* size as the longer one with values completed using the provided default.
17206-
* <p>
17207-
* Example:
17208-
* <pre class="groovyTestCase">
17209-
* def ab = ['a', 'b'].iterator()
17210-
* def abcd = ('a'..'d').iterator()
17211-
* def nums = (1..3)
17212-
* assert ['a1', 'b2', 'unknown3'] == ab.zipAll(nums, 'unknown', 0).collect{ a, b {@code ->} a + b }
17213-
* assert ['a1', 'b2', 'c3', 'd0'] == abcd.zipAll(nums, 'unknown', 0).collect{ a, b {@code ->} a + b }
17214-
* </pre>
17215-
*
17216-
* @param left an Iterator
17217-
* @param right an Iterable
17218-
* @return an iterator of all the pairs from left and right
17219-
* @since 5.0.0
17220-
*/
17221-
public static <U, V> Iterator<Tuple2<U, V>> zipAll(Iterator<U> left, Iterable<V> right, U leftDefault, V rightDefault) {
17222-
return zipAll(left, right.iterator(), leftDefault, rightDefault);
17223-
}
17224-
1722517166
private static final class ZipAllIterator<U, V> implements Iterator<Tuple2<U, V>> {
1722617167
private final Iterator<U> left;
1722717168
private final Iterator<V> right;

0 commit comments

Comments
 (0)