Skip to content
Subhajit Sahu edited this page May 17, 2020 · 32 revisions

Combines values from iterables. 🏃 📼 📦 🌔 📒

Similar: [cartesianProduct], [zip].

iterable.zip(xs, [fm], [ft], [vd]);
// xs: iterables
// fm: map function (vs, i, xs)
// ft: till function (dones)
// vd: default value
const iterable = require('extra-iterable');

var x = [1, 2, 3];
var y = [4, 5];
[...iterable.zip([x, y])];
// [ [ 1, 4 ], [ 2, 5 ] ] (shortest)

[...iterable.zip([x, y], ([a, b]) => a + b)];
// [ 5, 7 ]

[...iterable.zip([x, y]), null, iterable.some];
// [ [ 1, 4 ], [ 2, 5 ] ] (shortest)

[...iterable.zip([x, y], null, iterable.every, 0)];
// [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (longest)

[...iterable.zip([x, y], null, iterable.head, 0)];
// [ [ 1, 4 ], [ 2, 5 ], [ 3, 0 ] ] (first)

references

Clone this wiki locally