Skip to main content

Function: zip()

zip<Values>(...iterables): Iterable<Values, any, any>

Returns an iterable that pairs up same-index values from the given iterables into tuples.

The iterables are iterated in parallel until the shortest one is done, at which point the returned iterable is done.

Type Parameters

Values extends [] | unknown[]

Parameters

iterables

...Readonly<{ [Key in string | number | symbol]: Iterable<Values[Key<Key>], any, any> }>

Returns

Iterable<Values, any, any>

Example

console.log(
pipe(
zip(
[1, 2, 3, 4],
[5, `sloth`, 7],
[8, 9, 10],
),
reduce(toArray()),
),
)
//=> [ [ 1, 5, 8 ], [ 2, 'sloth', 9 ], [ 3, 7, 10 ] ]

Since

v3.8.0

Defined in

splices.d.ts:1267