JSFiddle - React, Tailwind, and code Playground
JavaScript
function lazyProduct(sets,f,context){
if (!context) context=this;
var p=[],max=sets.length-1,lens=[];
for (var i=sets.length;i--;) lens[i]=sets[i].length;
function dive(d){
// document.write('computing depth:' + d + '<br />' + p.length + '<br />');
var a=sets[d], len=lens[d];
if (d==max) for (var i=0;i<len;++i) p[d]=a[i], f.apply(context,p);
else for (var i=0;i<len;++i) p[d]=a[i], dive(d+1);
p.pop();
}
dive(0);
}
// i presume you hav this from ret.js
var tokens = [
['0', '00', '01', '1', '10', '11'],
['@'],
['a', 'b', 'c', 'd', 'e', 'f'],
];
// build it
lazyProduct(
tokens,
function () {
document.write(
Array.prototype.slice.call(
arguments
).join('') + '<br />'
);
}
);