StreamUtils.zip(…) now treats infinite streams correctly.
When an infinite Stream was handed into StreamUtils.zip(…) as first argument, the resulting stream was infinite, too, while inverting the argument order was limiting the resulting stream to the length of the finite one. This is now fixed by actually evaluating whether we can advance on both of the streams and shortcutting the process if that is not possible on either of the streams, limiting the processing of the overall Stream to the shorter of the two as already advertised in the Javadoc. Fixes #2426.
This commit is contained in:
@@ -42,4 +42,13 @@ public class StreamUtilsTests {
|
||||
|
||||
assertThat(input).isEqualTo(output);
|
||||
}
|
||||
|
||||
@Test // #2426
|
||||
void combinesInfiniteStreamCorrectly() {
|
||||
|
||||
Stream<Long> indices = Stream.iterate(1L, n -> n + 1);
|
||||
Stream<String> lines = Stream.of("first line", "second line");
|
||||
|
||||
assertThat(StreamUtils.zip(indices, lines, (index, line) -> index + ":" + line).count()).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user