Yeah, it is a bit awkward. After reading this article a few years back, I wrote a simpler implementation of curry that transforms the function itself, rather than being called from within it, e.g.
var add = curry(function(a,b,c) { return a + b + c; });
7 comments
[ 3.1 ms ] story [ 22.1 ms ] threadinstead of this:
<code> function add (a,b,c){ if (arguments.length < this.add.length) { return curry(this.add,arguments,this); } return a+b+c; } </code>
we could have something like:
<code> function add (a,b,c) { return curry(arguments, 3, function (x,y,z) { return a+b+c; }; } </code>
which is arguably simpler and cleaner. However, one extra closure is used.. maybe it makes it more complicated for some?
But, overall, pretty clear and interesting article :o
http://osteele.com/sources/javascript/functional/