JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
JavaScript
const constant = value => () => value;
const noop = value => () => value();
const plus = left => right => (nextOp = noop) => nextOp(() => left() + right());
const minus = left => right => (nextOp = noop) => nextOp(() => left() - right());
const times = left => right => (nextOp = noop) => nextOp(() => left() * right());
const over = left => right => (nextOp = noop) => nextOp(() => left() / right());
const withOp = op => right => left => op(right)(left);
// ((2 + 4) * 6) + 2
let result =
plus(constant(2))(constant(4))
(withOp(times)(constant(6)))
(withOp(plus)(constant(2)))();
console.log('((2 + 4) * 6) + 2', result());
// 8 - (1 + 3)
result = minus(constant(8))(plus(constant(1))(constant(3))())();
console.log('8 - (1 + 3)', result());