Skip to content

Instantly share code, notes, and snippets.

Created August 17, 2014 22:54
Show Gist options
  • Save anonymous/0c09972f8daeac5c3890 to your computer and use it in GitHub Desktop.
Save anonymous/0c09972f8daeac5c3890 to your computer and use it in GitHub Desktop.
// 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