3 ms·
You can indeed use transducers in asynchronous contexts. In fact, that is what intrigues me most about the abstraction. Transducers are defined such that you
by kbeaty 12y ago
You can indeed use transducers in asynchronous contexts. In fact, that is what intrigues me most about the abstraction.
Transducers are defined such that you can abstract the context of input, output and iteration and focus on the transformation of each element from an independent source individually. The implementation of each transducer accepts another transformation in a "pipeline" (eventually the output sink) and accepts an input during an external iteration process. The implementation decides what to do with it (map changes with a function, filter ignores certain values with a predicate, etc.) You can also define transducers that send multiple values for each input (think string.split) or some that do not send any until completion (think buffered results).
Since the iteration source and sink are abstracted from the transformation, you can use the same transformation in other contexts (Promises, event streams, IO streams, CSP, etc.)
I've been experimenting with transducers in asynchronous contexts in JavaScript if anyone is interested, for example:
[1]: http://simplectic.com/projects/underscore-transducer/ http://simplectic.com/projects/underscore-transducer/
[2]: http://simplectic.com/projects/underarm/ http://simplectic.com/projects/underarm/
[3]: https://github.com/transduce/transduce-async https://github.com/transduce/transduce-async
[4]: https://github.com/kevinbeaty/transduce-stream https://github.com/kevinbeaty/transduce-stream
[5]: https://github.com/transduce/transduce-push https://github.com/transduce/transduce-push
[6]: https://github.com/transduce/transduce-then https://github.com/transduce/transduce-then