Skip to content
Subhajit Sahu edited this page Dec 28, 2022 · 8 revisions

Combine matching entries from all ilists.

Similar: cartesianProduct, zip.


function zip(xs, fm, ft, vd?)
// xs: all ilists
// fm: map function (vs, k)
// ft: end function (dones) [some]
// vd: default value
const xilists = require('extra-ilists');
const array = require('extra-array');

var x = [['a', 'b', 'c'], [1, 2, 3]];
var y = [['a', 'b'], [10, 20]];
xilists.zip([x, y]).map(c => [...c]);
// → [ [ 'a', 'b' ], [ [ 1, 10 ], [ 2, 20 ] ] ] (shortest)

xilists.zip([x, y], ([a, b]) => a + b).map(c => [...c]);
// → [ [ 'a', 'b' ], [ 11, 22 ] ]

xilists.zip([x, y], null, array.some).map(c => [...c]);
// → [ [ 'a', 'b' ], [ [ 1, 10 ], [ 2, 20 ] ] ] (shortest)

xilists.zip([x, y], null, array.every, 0).map(c => [...c]);
// → [ [ 'a', 'b', 'c' ], [ [ 1, 10 ], [ 2, 20 ], [ 3, 0 ] ] ] (longest)


References

Clone this wiki locally