Skip to content

Instantly share code, notes, and snippets.

@gowon
Created June 25, 2015 23:33
Show Gist options
  • Select an option

  • Save gowon/d9f50c0506c888a73aae to your computer and use it in GitHub Desktop.

Select an option

Save gowon/d9f50c0506c888a73aae to your computer and use it in GitHub Desktop.
Javascript Currying Example
// Example of a currying methods
// https://medium.com/@kbrainwave/currying-in-javascript-ce6da2d324fe
var currier = function(fn) {
var args = Array.prototype.slice.call(arguments, 1);
return function() {
return fn.apply(this, args.concat(
Array.prototype.slice.call(arguments, 0)));
};
};
// example function
var sequence = function(start, end) {
var result = [];
for(var i = start; i <= end; i++) {
result.push(i);
}
return result;
};
//Example use of currying
var seq5 = currier(sequence, 1);
seq5(5); // [1, 2, 3, 4, 5];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment