cartesianProduct - nodef/extra-map GitHub Wiki

List cartesian product of maps.

Similar: cartesianProduct, zip.

function cartesianProduct(xs, fm)
// xs: maps
// fm: map function (vs, i)
const map = require('extra-map');

var x = new Map(['a', 1],  ['b', 2], ['c', 3](/nodef/extra-map/wiki/'a',-1],--['b',-2],-['c',-3));
var y = new Map(['d', 10], ['e', 20](/nodef/extra-map/wiki/'d',-10],-['e',-20));
[...map.cartesianProduct([x, y])];
// → [
// →   Map(2) { 'a' => 1, 'd' => 10 },
// →   Map(2) { 'a' => 1, 'e' => 20 },
// →   Map(2) { 'b' => 2, 'd' => 10 },
// →   Map(2) { 'b' => 2, 'e' => 20 },
// →   Map(2) { 'c' => 3, 'd' => 10 },
// →   Map(2) { 'c' => 3, 'e' => 20 }
// → ]

[...map.cartesianProduct([x, y], a => map.max(a))];
// → [
// →   [ 'd', 10 ],
// →   [ 'e', 20 ],
// →   [ 'd', 10 ],
// →   [ 'e', 20 ],
// →   [ 'd', 10 ],
// →   [ 'e', 20 ]
// → ]

References