@extra-set/cartesian-product

Lists cartesian product of sets. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

Usage no npm install needed!

<script type="module">
  import extraSetCartesianProduct from 'https://cdn.skypack.dev/@extra-set/cartesian-product';
</script>

README

Lists cartesian product of sets. :package: :smiley_cat: :running: :vhs: :moon: :scroll: :newspaper: :blue_book:

This is part of package extra-set.


set.cartesianProduct(xs, fn);
// xs: sets
// fn: map function (vs, vs)
const set = require("extra-set");

var x = new Set([1, 2, 3]);
var y = new Set([10, 20]);
[...set.cartesianProduct([x, y])];
// [
//   Set(2) { 1, 10 },
//   Set(2) { 1, 20 },
//   Set(2) { 2, 10 },
//   Set(2) { 2, 20 },
//   Set(2) { 3, 10 },
//   Set(2) { 3, 20 }
// ]

[...set.cartesianProduct([x, y], a => set.max(a)[1])];
// [ 10, 20, 10, 20, 10, 20 ]


References