Skip to content

Instantly share code, notes, and snippets.

@joe-crick
Created February 7, 2018 05:43
Show Gist options
  • Save joe-crick/3066d232cf22ab513750d54e6a060df8 to your computer and use it in GitHub Desktop.
Save joe-crick/3066d232cf22ab513750d54e6a060df8 to your computer and use it in GitHub Desktop.
JS Curry Example
// A sample Currying function
const partial = (f, ...as) => {
if (as.length === 0) { return f.call(); }
const a = as.shift();
if (a === undefined) { return f; }
const p = f.bind(f, a);
return partial(p, ...as);
}
// Composition function
const $ = f => (g, x) => x === undefined ? x => f(g(x)) : f(g(x));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment