Skip to content

Instantly share code, notes, and snippets.

@renaudtertrais
Last active February 10, 2017 12:45
Show Gist options
  • Save renaudtertrais/f5f38bc8f34e7a8459b00f373331006f to your computer and use it in GitHub Desktop.
Save renaudtertrais/f5f38bc8f34e7a8459b00f373331006f to your computer and use it in GitHub Desktop.
Simple ES6 partial function
const partial = (fn, ...args) => partialApply(fn, args);
const partialApply = (fn, args) => fn.bind(null, ...args);
// example
const add = (a, b) => a + b;
const sum = (...args) => args.reduce(add, 0);
const add10 = partial(sum, 4, 6);
const add40 = partialApply(sum, [5, 15, 20]);
sum(1,2,3) // 6
add10(10) // 20
add40(add10()) // 50
@renaudtertrais
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment