/** * Returns a sequential {@code EntryStream} containing {@code Entry} objects * composed from corresponding key and value in given two lists. * * <p> * The keys and values are accessed using {@link List#get(int)}, so the * lists should provide fast random access. The lists are assumed to be * unmodifiable during the stream operations. * * @param <K> the type of stream element keys * @param <V> the type of stream element values * @param keys the list of keys, assumed to be unmodified during use * @param values the list of values, assumed to be unmodified during use * @return a new {@code EntryStream} * @throws IllegalArgumentException if length of the lists differs. * @see StreamEx#zip(List, List, BiFunction) * @since 0.2.1 */ public static <K, V> EntryStream<K, V> zip(List<K> keys, List<V> values) { return of(new RangeBasedSpliterator.ZipRef<>(0, checkLength(keys.size(), values.size()), SimpleImmutableEntry::new, keys, values)); }
/** * Returns a sequential {@code DoubleStreamEx} containing the results of * applying the given function to the corresponding pairs of values in given * two arrays. * * @param first the first array * @param second the second array * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding array elements. * @return a new {@code DoubleStreamEx} * @throws IllegalArgumentException if length of the arrays differs. * @since 0.2.1 */ public static DoubleStreamEx zip(double[] first, double[] second, DoubleBinaryOperator mapper) { return of(new RangeBasedSpliterator.ZipDouble(0, checkLength(first.length, second.length), mapper, first, second)); }
/** * Returns a sequential {@code LongStreamEx} containing the results of * applying the given function to the corresponding pairs of values in given * two arrays. * * @param first the first array * @param second the second array * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding array elements. * @return a new {@code LongStreamEx} * @throws IllegalArgumentException if length of the arrays differs. * @since 0.2.1 */ public static LongStreamEx zip(long[] first, long[] second, LongBinaryOperator mapper) { return of(new RangeBasedSpliterator.ZipLong(0, checkLength(first.length, second.length), mapper, first, second)); }
/** * Returns a sequential {@code IntStreamEx} containing the results of * applying the given function to the corresponding pairs of values in given * two arrays. * * @param first the first array * @param second the second array * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding array elements. * @return a new {@code IntStreamEx} * @throws IllegalArgumentException if length of the arrays differs. * @since 0.2.1 */ public static IntStreamEx zip(int[] first, int[] second, IntBinaryOperator mapper) { return of(new RangeBasedSpliterator.ZipInt(0, checkLength(first.length, second.length), mapper, first, second)); }
/** * Returns a sequential {@code StreamEx} containing the results of applying * the given function to the corresponding pairs of values in given two * lists. * * <p> * The list values are accessed using {@link List#get(int)}, so the lists * should provide fast random access. The lists are assumed to be * unmodifiable during the stream operations. * * @param <U> the type of the first list elements * @param <V> the type of the second list elements * @param <T> the type of the resulting stream elements * @param first the first list, assumed to be unmodified during use * @param second the second list, assumed to be unmodified during use * @param mapper a non-interfering, stateless function to apply to each pair * of the corresponding list elements. * @return a new {@code StreamEx} * @throws IllegalArgumentException if length of the lists differs. * @see EntryStream#zip(List, List) * @since 0.2.1 */ public static <U, V, T> StreamEx<T> zip(List<U> first, List<V> second, BiFunction<? super U, ? super V, ? extends T> mapper) { return of(new RangeBasedSpliterator.ZipRef<>(0, checkLength(first.size(), second.size()), mapper, first, second)); }