-
Notifications
You must be signed in to change notification settings - Fork 1
zip
Subhajit Sahu edited this page Dec 5, 2022
·
15 revisions
Combine matching entries from maps.
Similar: cartesianProduct, zip.
function zip(xs, fm, fe, vd?)
// xs: maps
// fm: map function (vs, k)
// fe: end function (dones) [array.some]
// vd: default value
const map = require('extra-map');
const array = require('extra-array');
var x = new Map([['a', 1], ['b', 2], ['c', 3]]);
var y = new Map([['a', 10], ['b', 20]]);
map.zip([x, y]);
// → Map(2) { 'a' => [ 1, 10 ], 'b' => [ 2, 20 ] } (shortest)
map.zip([x, y], ([a, b]) => a + b);
// → Map(2) { 'a' => 11, 'b' => 22 }
map.zip([x, y], null, array.some);
// → Map(2) { 'a' => [ 1, 10 ], 'b' => [ 2, 20 ] } (shortest)
map.zip([x, y], null, array.every, 0);
// → Map(3) { 'a' => [ 1, 10 ], 'b' => [ 2, 20 ], 'c' => [ 3, 0 ] } (longest)