Real curry behavior in JavaScript
JavaScript
Switch branches/tags
Nothing to show
Latest commit 44fd66d May 29, 2013 @eborden Update README.md
Permalink
Failed to load latest commit information.
lib
tests
README.md

README.md

JavaScript Curry

Many JavaScript curry functions are actually implementations of partial application. This module implements true curry behavior in JavaScript.

True curry behavior means only accepting a single argument at a time and only executing upon application of all arguments. [citation]

curried = curry(function (a, b, c) {
	return a + b + c;
});
curried(1)(2)(3); //6

curriedOne = $curried(1);
curriedOne(2)(3); //6

Reverse Currying is also possible

//verbose
curried = curry(function (a, b, c) {
	return a + b + c;
}, true);

//single argument convenience
curried = curry.r(function (a, b, c) {
	return a + b + c;
});

curried('a')('b')('c'); //'cba'

Tests

Tests are written in jasmine. They can be run at http://tryjasmine.com/

To run from the command line:

npm install jasmine-node
jasmine-node path/to/js-curry

Benchmark

http://jsperf.com/js-curry-bench/3