Last active
October 27, 2020 07:09
-
-
Save ericelliott/f0a8fd662111ea2f569e to your computer and use it in GitHub Desktop.
Generic Partial Application Function https://jsbin.com/biyupu/edit?html,js,output
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
// 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