3 ms·
I had a similar epiphany while learning about regular expressions in Perl. That connection with text processing is what helped me understand list comprehensions
by ultimape 12y ago
I had a similar epiphany while learning about regular expressions in Perl. That connection with text processing is what helped me understand list comprehensions. They seem strikingly similar.
For JS, I personally prefer lo-dash for this kind of work, or dropping in polyfills from MDN.
For some context, here are .map functions applied to normal arrays
http://jsperf.com/native-vs-array-js-vs-underscore/54 http://jsperf.com/native-vs-array-js-vs-underscore/54
I've been looking for similar libraries that work on typed-arrays because they are so much more efficient when working with web-workers or with raw canvas data. My attempts at hacking it in feel like they are just bad ideas: http://jsperf.com/float32array-map/2 http://jsperf.com/float32array-map/2
- grayrest 12y agoMost people use underscore/lodash for this stuff. The difference is that the js transducers libraries don't create intermediate arrays, only do enough work to produce the requested output, and work on top of anything that can be coerced into the iteration protocol. I've seen demos of using Facebook's Immutable JS, CSP.js [1], and I don't see why you couldn't put them on top of Typed Arrays or a FRP library like Kefir. [1] http://jlongster.com/s/nationjs-slides/ http://jlongster.com/s/nationjs-slides/
- ultimape 12y agoYeah, the overhead of creating intermediate typed arrays is exactly what I'm trying to avoid with this.