Settings

Theme

Curried JavaScript functions

svendtofte.com

12 points by juvenn 16 years ago · 7 comments

Reader

dugmartin 16 years ago

Here is a great functional JavaScript library if you don't want to build it up yourself:

http://osteele.com/sources/javascript/functional/

d0m 16 years ago

Suggestion:

instead 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

  • panic 16 years ago

    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; });
    
    You can find the code at http://ianhenderson.org/curry.js if you're interested.
  • d0m 16 years ago

    <-- Fail with <code> !

Spreadsheet 16 years ago

I have a question about "it" in ML. How is it useful?

shawndumas 16 years ago

I thought this was a partial.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection