Last active
June 7, 2019 03:47
-
-
Save mikaelbr/3808aec0ac6b5d641c28fda5534f5ee2 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 scope = {}; | |
| function def(id, fn) { | |
| scope[id] = fn; | |
| } | |
| function explode(id) { | |
| return scope[id] ? [id] : id.split('\u200d'); | |
| } | |
| function getFns(id) { | |
| return explode(id).map(function(ii) { | |
| if (!scope[ii]) | |
| throw new Error(`undefined is not a function π€‘. | |
| (But seriously, ${ii} isn't defined as a function in the scope.)`); | |
| return scope[ii]; | |
| }); | |
| } | |
| function compose(fns) { | |
| return arg => | |
| fns.reduceRight(function(prev, fn) { | |
| return fn(prev); | |
| }, arg); | |
| } | |
| function invoke(id, arg) { | |
| return compose([compose, getFns])(id)(arg); | |
| } | |
| def('π¨', console.log); | |
| def('π»', arg => arg.toUpperCase()); | |
| invoke('π¨βπ»', 'hello, world!'); | |
| //=> HELLO, WORLD! |
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
| π© Example syntax: | |
| π¨ β¬ οΈ console.log | |
| π» β¬ οΈ toUpperCase | |
| "hello, world!" β‘οΈ π¨βπ» | |
| π© Outputs: "HELLO, WORLD!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment