Skip to content

Instantly share code, notes, and snippets.

@mattidupre
Last active August 29, 2015 13:56
Show Gist options
  • Save mattidupre/8796059 to your computer and use it in GitHub Desktop.
Save mattidupre/8796059 to your computer and use it in GitHub Desktop.
Combines functions into single chain. Similar to lodash's _.compose, but updates the first argument to the return value of the previous function.
function compose() {
var functions = arguments;
return function() {
for (var n=0; n<functions.length; n++) {
var result = functions[n].apply(functions[n], arguments);
if (result === false) {
return false;
}
arguments[0] = result;
}
return arguments[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment