Last active
February 5, 2016 15:30
-
-
Save nikitadyumin/6551b7de5bde94060b2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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