3 ms·
But shouldn't not generating intermediate collections be the obvious way to do it? In Rust for example map/filter/etc use normal iterators and don't create inte
by dataangel 5y ago
But shouldn't not generating intermediate collections be the obvious way to do it? In Rust for example map/filter/etc use normal iterators and don't create intermediate collections. C++ ranges have this property too.
- bjoli 5y agoWell, in scheme (my language of choice), if you chain map and filter like so: (map square (filter even? lst)) filter will return a new list that map will map over and return yet another list (map and filter doesn't modify its arguments). With transducers you can avoid that. And transducers can be passed to other functions that can use them in any context. You can create one transducer that filters even numbers and squares the result and re-use it either by transducing over a list, or as a processing part of an async channel. It is like a streaming data protocol, in that way. Transducers transform data.