Skip to content

Instantly share code, notes, and snippets.

@ayinlaaji
Created April 26, 2018 18:30
Show Gist options
  • Save ayinlaaji/b79ff7d68709c8aff7a9362f8ac553e3 to your computer and use it in GitHub Desktop.
Save ayinlaaji/b79ff7d68709c8aff7a9362f8ac553e3 to your computer and use it in GitHub Desktop.
Understanding partial applications
// 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