Skip to content

Instantly share code, notes, and snippets.

@nikitadyumin
Last active February 5, 2016 15:30
Show Gist options
  • Select an option

  • Save nikitadyumin/6551b7de5bde94060b2f to your computer and use it in GitHub Desktop.

Select an option

Save nikitadyumin/6551b7de5bde94060b2f to your computer and use it in GitHub Desktop.
const one = () => 1;
const two = () => 2;
const three = () => 3;
function op(fn) {
return function() {
return (vars) => Array.from(arguments)
.map(x => typeof x === 'function' ? x(vars) : +x).reduce(fn)
};
}
const v = name => vars => vars[name];
const plus = op((x,y) => x + y);
const mult = op((x,y) => x * y);
const result = plus(one(), 10, v('foo'), mult(two(), three(), 5));
console.log(result({ foo:1 })); // 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment