Skip to content

Instantly share code, notes, and snippets.

@mmckegg
Created October 13, 2013 02:00
Show Gist options
  • Save mmckegg/6957203 to your computer and use it in GitHub Desktop.
Save mmckegg/6957203 to your computer and use it in GitHub Desktop.
Flow control for object building - passes object as first param.
function flow(target, items, cb){
forEach(items, function(item, next){
if (Array.isArray(item)){
item[0].apply(this, [target].concat(item.slice(1), cb))
} else {
item(target, next)
}
}, function(err){
if (err) return cb&&cb(err)
cb(null, target)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment