JSFiddle - React, Tailwind, and code Playground
JavaScript
Function.prototype.curry = function(){
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function() {
// context set to null, which will cause `this` to refer to the window
return that.apply(null, args.concat(slice.apply(arguments)));
};
};
function multiply(a, b, history) {
return [a * b, [a + " * " + b].concat(history)];
}
function back(history) {
return [history[0], history.slice(1)];
}
var myCalc = [];
var multiplyPi = multiply.curry(Math.PI);
var test = bindState(multiplyPi.curry(1), function (prod) {
alert(prod);
return back;
});
function bindState(g, f) {
return function (s) {
var a = g(s);
return f(a[0])(a[1]);
};
}
alert(test(myCalc)[0]);