Skip to content

Instantly share code, notes, and snippets.

@davidjbeveridge
Created August 19, 2014 16:23
Show Gist options
  • Save davidjbeveridge/6196d24313cab801522a to your computer and use it in GitHub Desktop.
Save davidjbeveridge/6196d24313cab801522a to your computer and use it in GitHub Desktop.
Partial Application
// Some assertion functions we can play with
function assert(condition, message) {
if(!condition) {
throw new Error(message);
}
}
function assert_equal(obj1, obj2) {
assert(obj1 === obj2, 'Expected '+obj1+' to equal '+obj2+'.');
}
/***************************************************************************
* Implement partial application:
*/
function partial(fn) {
// fill in here
}
function sum3(a,b,c) { return a+b+c; }
var sumWith5 = partial(sum3, 5);
assert_equal(typeof sumWith5, 'function');
assert_equal(sumWith5(0,0), 5);
assert_equal(sumWith5(10,0), 15);
assert_equal(sumWith5(3,3), 11);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment