Skip to content

Instantly share code, notes, and snippets.

@mikaelbr mikaelbr/emoji-lang.js
Last active Jun 7, 2019

Embed
What would you like to do?
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!
📩 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
You can’t perform that action at this time.