4 ms·
`map` and `filter` should take their functional argument first, then data second.
by _callcc 10y ago
`map` and `filter` should take their functional argument first, then data second.
- krapp 10y agoIn 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.
- madeofpalk 10y agomap and filter are already builtins anyway, so it's kind of a moot point. It sure is confusing why the author implemented these functions...
- nilliams 10y agoCross-browser usage? Map and filter aren't in IE8, which is still in wider use than a lot of people would like to pretend.
- madeofpalk 10y agoWell, 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.
- nilliams 10y ago>> 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).
- jestar_jokin 10y agoJust 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://ramdajs.com/ http://fr.umio.us/why-ramda/ http://fr.umio.us/why-ramda/
- jdd 10y agoBTW there's lodash/fp modules too: https://github.com/lodash/lodash/wiki/FP-Guide https://github.com/lodash/lodash/wiki/FP-Guide https://simonsmith.io/dipping-a-toe-into-functional-js-with-lodash-fp/ https://simonsmith.io/dipping-a-toe-into-functional-js-with-... https://medium.com/@jdalton/just-a-heads-up-the-lazy-js-benchmarks-referenced-are-comparing-3-yr-old-versions-of-libraries-f9c45eca3976#.iad7ggcmk https://medium.com/@jdalton/just-a-heads-up-the-lazy-js-benc...
- vortico 10y agoIt makes it look nicer in Coffeescript to have the function last, but yes, I agree.
- Kiro 10y agoWhy?
- dozzie 10y agoBecause that's the convention everywhere else.
- BillinghamJ 10y agoRight, but that's not the convention in Node. Anonymous functions always go last.
- patricklynch 10y agoBecause 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 https://www.youtube.com/watch?v=m3svKOdZijA)
- deleted 10y ago[deleted]