zip - nodef/extra-lists GitHub Wiki

Combine matching entries from all lists.

Similar: cartesianProduct, zip.

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

var x = ['a', 'b', 'c'], [1, 2, 3](/nodef/extra-lists/wiki/'a',-'b',-'c'],-[1,-2,-3);
var y = ['a', 'b'], [10, 20](/nodef/extra-lists/wiki/'a',-'b'],-[10,-20);
xlists.zip([x, y]).map(c => [...c]);
// → [ [ 'a', 'b' ], [ [ 1, 10 ], [ 2, 20 ] ] ] (shortest)

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

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

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

References