Skip to content

Instantly share code, notes, and snippets.

@PanJarda
Last active August 24, 2016 20:39
Show Gist options
  • Save PanJarda/279e3b5941d0b429e2050c1c6087b50f to your computer and use it in GitHub Desktop.
Save PanJarda/279e3b5941d0b429e2050c1c6087b50f to your computer and use it in GitHub Desktop.
// partially invoked function
function add(x, y) {
if (arguments.length == 1)
return function(y) {return x + y}
return x + y
}
// pipe function for chaining function calls
function pipe() {
var args = Array.prototype.slice.call(arguments)
var d = args.shift()
var f = args.shift()
args.unshift(f(d))
if (args.length > 1)
return pipe.apply(this, args)
return args[0]
}
// console.log(add(4, 2))
pipe(2, add(4), console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment