Last active
August 24, 2016 20:39
-
-
Save PanJarda/279e3b5941d0b429e2050c1c6087b50f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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