Skip to content
Subhajit Sahu edited this page Jun 17, 2020 · 10 revisions

Combines entries from maps. 🏃 📼 📦 🌔 📒

Similar: cartesianProduct, zip.

map.zip(xs, [fm], [ft], [vd]);
// xs: maps
// fm: map function (vs, k, null)
// ft: till function (dones) (some)
// vd: default value
const entries = require('extra-entries');
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)

map.zip([x, y], null, array.head, 0);
// Map(3) { 'a' => [ 1, 10 ], 'b' => [ 2, 20 ], 'c' => [ 3, 0 ] } (first)

references

Clone this wiki locally