Skip to content
Subhajit Sahu edited this page Feb 3, 2021 · 15 revisions

Combines matching entries from maps. 🏃 📼 📦 🌔 📒

Similar: cartesianProduct, zip.

map.zip(xs, [fm], [ft], [vd]);
// xs: maps
// fm: map function (vs, k)
// ft: till function (dones) (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)

references

Clone this wiki locally