Created
April 26, 2018 18:30
-
-
Save ayinlaaji/b79ff7d68709c8aff7a9362f8ac553e3 to your computer and use it in GitHub Desktop.
Understanding partial applications
This file contains 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
// Understanding partial applications | |
// Github Gist @ayinlaaji | |
function partiallyApply(func) { | |
const someArgs = Array.prototype.slice.call(arguments, 1); | |
return giveMeRemainingArgs; | |
//Hoisting :D | |
function giveMeRemainingArgs() { | |
const remainingArgs = Array.prototype.slice.call(arguments); | |
const fullArgs = someArgs.concat(remainingArgs); | |
return func.apply(null, fullArgs); | |
} | |
} | |
const theBeast = (a, b, c) => a + b + c; | |
const appliedBeast = partiallyApply(theBeast, 1); | |
const res0 = appliedBeast(2, 3); | |
console.log(res0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment