-
-
Save fazlurr/349d680004065a6c2488ea37c22f2622 to your computer and use it in GitHub Desktop.
Generic Partial Application Function https://jsbin.com/biyupu/edit?html,js,output
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
// Generic Partial Application Function | |
// https://jsbin.com/biyupu/edit?html,js,output | |
// https://gist.github.com/ericelliott/f0a8fd662111ea2f569e | |
// partialApply(targetFunction: Function, ...fixedArgs: Any[]) => | |
// functionWithFewerParams(...remainingArgs: Any[]) | |
const partialApply = (fn, ...fixedArgs) => { | |
return function (...remainingArgs) { | |
return fn.apply(this, fixedArgs.concat(remainingArgs)); | |
}; | |
}; | |
test('add10', assert => { | |
const msg = 'partialApply() should partially apply functions' | |
const add = (a, b) => a + b; | |
const add10 = partialApply(add, 10); | |
const actual = add10(5); | |
const expected = 15; | |
assert.equal(actual, expected, msg); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment