Live data from Hacker News

Fun.js – Just a sketch

blog.fogus.me

21–22 of 22 posts

Re: Fun.js – Just a sketch

#21
Some questions from JS novice:

Why map isn't implemented:

    function map(fun, coll) {
      if (exists(coll)) return _map(fun)(coll);
      return _map(fun);
    }
Why use arguments when you can name your parameter in declaration?

And why _map is defined in global scope? Shouldn't it be better defined inside map function? What are up/downsides in performance for this move?

Re: Fun.js – Just a sketch

#22
post #19

Very interesting post but I'm having trouble with one thing. pipeline(5) returns 5. When I try to follow that path, I get to this: reduce(function(l,r) { return r(l); }, seed, funs) with seed=5 and funs=[] (an empty array). How does that reduction evaluate to 5? In other words, what is "r(l)" when l=5 and r=the first member of an empty array?

In reduce the accumulator starts as the seed and is changed in the forEach for each elem. Since there are so elems (funs) the accumulator never changes and returns as the value of seed (5).

Of course. Shoulda seen that. ;) forEach on an empty collection returns immediately. Thanks.
Post reply on HN