cartesian-map
This small library contains a map
-like function that iterates over elements of an array (or over characters of a string), calls a user-provided function on each, and returns the cartesian product of the lists returned by the function for each of the elements.
Examples
Array.prototype.cartesianMap = require('cartesian-map');
String.prototype.cartesianMap = require('cartesian-map');
console.log([1, 2, 3].cartesianMap(() => [false, true]));
console.log([2, 11, 24, 39].cartesianMap((item, index) => item % 2 === 0 ? [item] : [item, item + index]));
console.log([2, 11, 24, 39].cartesianMap((item, index) => item % 2 === 0 ? item : [item, item + index]));
console.log('Foo Bar'.cartesianMap((char) => char === char.toLowerCase() ? char : [char, char.toLowerCase()]));
console.log('bar'.cartesianMap((char) => ['', char]));