JSFiddle - React, Tailwind, and code Playground
JavaScript
function loeb(formulas) {
function evaluate(formula) { return function() {
return formula(results);
} }
var results = formulas.map(evaluate);
return results;
}
console.log("spreadsheet result: ", loeb([
function(cells) { return 2; },
function(cells) { return 3; },
function(cells) { return cells[0]() + cells[1](); }
]).map(function(x){ return x(); }))
function moeb(map) { return function (formulas) {
function evaluate(formula) { return function() {
return formula(results);
} }
var results = map(evaluate)(formulas);
return results;
} }
function map(func) { return function(array) {
return array.map(func);
} }
var the_same_loeb = moeb(map);
function id(x) {
return x;
}
var fix = moeb(id);
var factorial = fix(function(fac) { return function(x) {
return x > 0 ? x * fac()(x - 1) : 1;
} })();
console.log("factorial of 3 is", factorial(3));