@iterables/zip
Combine iterables into a list of tuples, where the Nth tuple is comprised of
the Nth element from each iterable.
const zip = require('@iterables/zip')
const iter = zip('abc', [1, 2, 3], 'xyz')
console.log(Array.from(iter))
const map = new Map()
map.set('a', 3)
map.set('b', 0)
console.log(...zip(...map))
console.log(...zip.longest(9999)([1,2], [1,2,3]))
Installation
$ npm install --save @iterables/zip
API
zip(...iterables) -> Iterator<Array<T>>
iterables
: any Iterator
— a generator instance, Array
, Map
, String
, or Set
Returns a zipped iterator. If iterables
are of different lengths, the resulting
iterator will be the same length as the shortest iterable.
zip.longest(fill) -> Generator
Returns a zipped iterator. If iterables
are of different lengths, the resulting
iterator will be the same length as the longest iterable. Missing values from
the shorter iterables will be replaced with fill
.
License
MIT