Created
August 17, 2014 22:54
-
-
Save anonymous/0c09972f8daeac5c3890 to your computer and use it in GitHub Desktop.
This file contains 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
// this is ULTRA specialized to our use case | |
function cbmap(array, fn, input) { | |
fn( | |
array[0] | |
, input||[] | |
, function (output) { | |
cbmap(array.slice(1), fn, output) | |
} | |
) | |
} | |
// how we would use it | |
cbmap(command.reverse(), function executor (operator, input, next) { | |
if (Object.prototype.toString.call(operator) === '[object Array]') | |
// uh oh | |
else if (typeof commands[operator] === 'function') | |
commands[operator](input, next) | |
else if (typeof operator === 'string' && !isNaN(operator)) | |
next([].concat(Number(operator), input)) | |
else | |
next([].concat(operator, input)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment