/*
Equivalent to combine, but accepts an Iterable and takes the first value
only from that iterable. (non-Javadoc)

@see com.oath.cyclops.types.Zippable#zip(java.lang.Iterable,
java.util.function.BiFunction)
555570
@Override
    public <T2, R> Future<R> zip(final Iterable<? extends T2> app, final BiFunction<? super T, ? super T2, ? extends R> fn) {

      return Future.of(future.thenCombine(Future.fromIterable(app).getFuture(), fn));
    }
215521
def pairwise(
    iterable: Iterable,
    default_value: Any,
) -> Iterable[Tuple[Any, Any]]:
    
    a, b = tee(iterable)
    _ = next(b, default_value)
    return zip_longest(a, b, fillvalue=default_value)
658919
public static <A, B, C, R> Stream<R> zip(final Collection<? extends A> a, final Collection<? extends B> b, final Collection<? extends C> c,
            final TriFunction<? super A, ? super B, ? super C, R> zipFunction) {
        return zip(a.iterator(), b.iterator(), c.iterator(), zipFunction);
    }
1276924
public static ShortStream zip(final ShortStream a, final ShortStream b, final ShortStream c, final ShortTriFunction<Short> zipFunction) {
        return Stream.zip(a, b, c, zipFunction).mapToShort(ToShortFunction.UNBOX);
    }
892025
def _pairwise(iterable):
    
    a, b = itertools.tee(iterable)
    next(b, None)
    if sys.version_info.major == 2:
        return itertools.izip(a, b)
    else:
        return zip(a, b)
56697
@Override
    public <I> Lazy<Choice8<A, B, C, D, E, F, G, I>> lazyZip(
            Lazy<? extends Applicative<Function<? super H, ? extends I>, Choice8<A, B, C, D, E, F, G, ?>>> lazyAppFn) {
        return match(a -> lazy(a(a)),
                     b -> lazy(b(b)),
                     c -> lazy(c(c)),
                     d -> lazy(d(d)),
                     e -> lazy(e(e)),
                     f -> lazy(f(f)),
                     g -> lazy(g(g)),
                     h -> lazyAppFn.fmap(choiceF -> choiceF.<I>fmap(f -> f.apply(h)).coerce()));
    }
905512
public static <R> Stream<R> zip(final IntIterator a, final IntIterator b, final IntBiFunction<R> zipFunction) {
        return new IteratorStream<>(new ObjIteratorEx<R>() {
            @Override
            public boolean hasNext() {
                return a.hasNext() && b.hasNext();
            }

            @Override
            public R next() {
                return zipFunction.apply(a.nextInt(), b.nextInt());
            }
        });
    }
722695
public static <R> Stream<R> zip(final ByteIterator a, final ByteIterator b, final ByteBiFunction<R> zipFunction) {
        return new IteratorStream<>(new ObjIteratorEx<R>() {
            @Override
            public boolean hasNext() {
                return a.hasNext() && b.hasNext();
            }

            @Override
            public R next() {
                return zipFunction.apply(a.nextByte(), b.nextByte());
            }
        });
    }
913887
def split_in_pairs(arg: Iterable) -> Iterable[Tuple]:
    
    # We are using zip_longest with one clever hack:
    # https://docs.python.org/3/library/itertools.html#itertools.zip_longest
    # We create an iterator out of the list and then pass the same iterator to
    # the function two times. Thus the function consumes a different element
    # from the iterator each time and produces the desired result.
    iterator = iter(arg)
    return zip_longest(iterator, iterator)
1229498
def zipObject(self, values):
        
        result = {}
        keys = self.obj
        i = 0
        l = len(keys)
        while i < l:
            result[keys[i]] = values[i]
            l = len(keys)
            i += 1

        return self._wrap(result)
485814
public static <K, V> Map<K, V> zipMapPartial(Iterable<K> keys, Iterable<V> values)
  {
    Map<K, V> retVal = new LinkedHashMap<>();

    Iterator<K> keysIter = keys.iterator();
    Iterator<V> valsIter = values.iterator();

    while (keysIter.hasNext()) {
      final K key = keysIter.next();

      if(valsIter.hasNext()) retVal.put(key, valsIter.next());
      else break;
    }

    return retVal;
  }
1365813
public static CharStream zip(final char[] a, final char[] b, final char[] c, final CharTriFunction<Character> zipFunction) {
        return Stream.zip(a, b, c, zipFunction).mapToChar(ToCharFunction.UNBOX);
    }
523452
public static <R> Stream<R> zip(final long[] a, final long[] b, final long[] c, final LongTriFunction<R> zipFunction) {
        return zip(LongIteratorEx.of(a), LongIteratorEx.of(b), LongIteratorEx.of(c), zipFunction);
    }
1210746
public static <T1, T2, R> Maybe<R> combine(Maybe<? extends T1> maybe, Maybe<? extends T2> app,
            BiFunction<? super T1, ? super T2, ? extends R> fn) {
        return narrow(Single.fromPublisher(Future.fromPublisher(maybe.toFlowable())
                                .zip(Future.fromPublisher(app.toFlowable()), fn)).toMaybe());
    }
442960
public static <K, V> Map<K, V> zip(Collection<K> keys, Collection<V> values) {
		if (isEmpty(keys) || isEmpty(values)) {
			return null;
		}

		final List<K> keyList = new ArrayList<K>(keys);
		final List<V> valueList = new ArrayList<V>(values);

		final int size = Math.min(keys.size(), values.size());
		final Map<K, V> map = new HashMap<K, V>((int) (size / 0.75));
		for (int i = 0; i < size; i++) {
			map.put(keyList.get(i), valueList.get(i));
		}

		return map;
	}
1040102
@Override
    public <U> Future<Tuple2<T, U>> zip(final Iterable<? extends U> other) {
        return (Future) Zippable.super.zip(other);
    }
472196
@SuppressWarnings("resource")
    public static <R> Stream<R> zip(final Collection<? extends FloatStream> c, final FloatNFunction<R> zipFunction) {
        if (N.isNullOrEmpty(c)) {
            return Stream.empty();
        }

        final int len = c.size();
        final FloatIterator[] iters = new FloatIterator[len];
        int i = 0;

        for (FloatStream s : c) {
            iters[i++] = s.iteratorEx();
        }

        return new IteratorStream<>(new ObjIteratorEx<R>() {
            @Override
            public boolean hasNext() {
                for (int i = 0; i < len; i++) {
                    if (iters[i].hasNext() == false) {
                        return false;
                    }
                }

                return true;
            }

            @Override
            public R next() {
                final float[] args = new float[len];

                for (int i = 0; i < len; i++) {
                    args[i] = iters[i].nextFloat();
                }

                return zipFunction.apply(args);
            }
        }).onClose(newCloseHandler(c));
    }