Skip to content

Instantly share code, notes, and snippets.

@devdilson
Last active September 18, 2017 02:17
Show Gist options
  • Select an option

  • Save devdilson/15b8e53c8bc4df65c7b7bd6d10749d06 to your computer and use it in GitHub Desktop.

Select an option

Save devdilson/15b8e53c8bc4df65c7b7bd6d10749d06 to your computer and use it in GitHub Desktop.
A simple away of currying parameters into functions
/*
f -> the function
The curried methods will be called with N args that are used into the function f.
Tested in: https://stephengrider.github.io/JSPlaygrounds/
*/
const curry = (f) => {
const inner = (...args) => args.forEach(e => f(e)) || inner;
return inner;
}
let result = 0;
var sum = k => result += k;
curry(sum)(1, 2, 3)(1)()(12)()()()()(1);
result //20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment