### Question:
StreamUtils { private static <X, Y, Z> Stream<Z> zip(Stream<X> x, Stream<Y> y, BiFunction<X, Y, Z> f) { final Iterator<Y> iter = y.iterator(); return x.filter( it -> iter.hasNext()).map(it -> f.apply(it, iter.next())); }  static Stream<Tuple<X, Y>> zip(Stream<X> x, Stream<Y> y); @SafeVarargs static Optional<T> firstOptional(Supplier<Optional<T>> ... optionals);  }### Answer:
@Test void test_stream_zip() { Map<Integer, Integer> testee = StreamUtils.zip( IntStream.range(0, 3).boxed(), IntStream.range(0, 3).boxed().map(x->2*x)) .collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)); checkSameMap(testee); }
@Test void test_stream_zip_second_loger() { Map<Integer, Integer> testee = StreamUtils.zip( IntStream.range(0, 3).boxed(), IntStream.range(0, 4).boxed().map(x->2*x)) .collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)); checkSameMap(testee); }
@Test void test_stream_zip_first_loger() { Map<Integer, Integer> testee = StreamUtils.zip( IntStream.range(0, 4).boxed(), IntStream.range(0, 3).boxed().map(x->2*x)) .collect(Collectors.toMap(Tuple::getFirst, Tuple::getSecond)); checkSameMap(testee); }
@Test void checkAssertionA() { assertThrows(IllegalArgumentException.class, () -> StreamUtils.zip(null,null) ); }
@Test void checkAssertionB() { assertThrows(IllegalArgumentException.class, () -> StreamUtils.zip(IntStream.range(0, 4).boxed(),null) ); }