Skip to main content

Function: zip()

zip<Iterables>(...iterables: Iterables): ZipIterators<Iterables>

Creates an iterable with the elements of the input iterables zipped together. The opposite of unzip.

Type parameters

Type parameter
Iterables extends readonly IterableResolvable<any>[]

Parameters

ParameterTypeDescription
...iterablesIterablesThe iterables to zip together.

Returns

ZipIterators<Iterables>

A new iterable that yields the next value of each iterable in the list.

Example

import { zip } from '@sapphire/iterator-utilities';

const iterable1 = [1, 2, 3];
const iterable2 = ['a', 'b', 'c'];
const iterable3 = [true, false, true];

console.log(zip(iterable1, iterable2, iterable3));
// Output: [
// [1, 'a', true],
// [2, 'b', false],
// [3, 'c', true]
// ]

Source

projects/utilities/packages/iterator-utilities/src/lib/zip.ts:25