Hacker News new | ask | show | jobs
by _callcc 3628 days ago
`map` and `filter` should take their functional argument first, then data second.
4 comments

In a perfect world, map and filter would extend the Array prototype, which is how the language was designed to be extended.

That aside, to me, putting the data argument first would seem to make the code more readable.

map and filter are already builtins anyway, so it's kind of a moot point.

It sure is confusing why the author implemented these functions...

Cross-browser usage? Map and filter aren't in IE8, which is still in wider use than a lot of people would like to pretend.
Well, what browsers you support is obviously going to depend strongly on your particular site and use case. I work on a consumer-facing site for a national broadcaster which sets very aggressive browser support (oldest IE we support is IE11) which works fine for us.

Regardless, any sort of environment where you can do `import extend from 'just-extend';` is going to (have a way) support map and filter.

>> Regardless, any sort of environment where you can do `import extend from 'just-extend';` is going to (have a way) support map and filter.

That is not true for the now-fairly-common use case that browserify/webpack satisfy. I write code with ES6 module syntax and build with browserify (& babelify) to target the browser. But I still need to pull in modules like lodash.map/lodash.filter if I want to target IE8.

(I could use es5-shim but that makes for less portable code).

Just use Ramda, it's a utility library that "gets the argument order correct", and supports currying and other nice FP concepts.

http://ramdajs.com/

http://fr.umio.us/why-ramda/

It makes it look nicer in Coffeescript to have the function last, but yes, I agree.
Why?
Because then you can curry/partially apply functions independent of your data.

It's _not_ because it's convention everywhere else.

(I realize that only really makes sense if you know why it makes sense, so this video gives a pretty good explanation in ~30 minutes - https://www.youtube.com/watch?v=m3svKOdZijA)

Because that's the convention everywhere else.
Right, but that's not the convention in Node. Anonymous functions always go last.