Skip to content
wolfram77 edited this page Mar 27, 2020 · 32 revisions

Combines values from n iterables.

iterable.zip(x, [fn], [ths]);
// xs:  iterables
// fn:  combine function (a, b, c, ...)
// ths: this argument
// --> combined values
const iterable = require('extra-iterable');

var x = [1, 2, 3].values();
var y = [4, 5, 6].values();
var z = [0, 0, 0].values();
[...iterable.zip([x, y])];
// [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]

[...iterable.zip([x, y, z])];
// [ [ 1, 4, 0 ], [ 2, 5, 0 ], [ 3, 6, 0 ] ]

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

references

Clone this wiki locally