@mirei/ts-collections
    Preparing search index...

    Function zip

    • Combines source with other and optionally projects each aligned pair using zipper.

      Type Parameters

      • TElement

        Type of elements within source.

      • TSecond

        Type of elements within other.

      • TResult = [TElement, TSecond]

        Result type produced by zipper; defaults to [TElement, TSecond] when zipper is omitted.

      Parameters

      • source: Iterable<TElement>

        The primary sequence whose elements lead each pair.

      • other: Iterable<TSecond>

        The secondary sequence whose elements are paired with source.

      • Optionalzipper: Zipper<TElement, TSecond, TResult>

        Optional projection invoked with each [source, other] pair. When omitted, the tuples [source, other] are emitted.

      Returns IEnumerable<[TElement, TSecond]> | IEnumerable<TResult>

      A deferred sequence of projected results truncated to the length of the shorter input.

      Re-throws any error thrown while iterating either input sequence or executing zipper.

      Enumeration is lazy; pairs are produced on demand and iteration stops as soon as either input completes.

      const numbers = [1, 2, 3];
      const letters = ['a', 'b', 'c'];
      const zipped = zip(numbers, letters).toArray();
      console.log(zipped); // [[1, 'a'], [2, 'b'], [3, 'c']]

      const zippedWithSelector = zip(numbers, letters, (num, letter) => `${num}-${letter}`).toArray();
      console.log(zippedWithSelector); // ['1-a', '2-b', '3-c']