Transducing

Now, let's consider a performance problem in JavaScript that happens when we're dealing with large arrays and applying several map/filter/reduce operations. If you start with an array and apply such operations (via chaining, as we saw earlier in this chapter), you get the desired result, but many intermediate arrays are created, processed, and discarded—and that causes delays. If you are dealing with short arrays, the extra time won't make an impact, but if you are processing larger arrays (as in a big data process, maybe in Node, where you're working with the results of a large database query), then you will have cause to look for some optimization. We'll do this by learning about a new tool for composing functions: transducing ...

Get Mastering JavaScript Functional Programming - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.