Transducers.jl: Efficient Transducers for Julia
github.com
github.com
Transducers are oblivious to the context in which they are being used, and transforms each element in turn. They can be extended at each end and do not create intermediate results. Thay are of course not only useful when tranforming collections, but also in places where data flows in one direction like Async channels.
I wrote this (and the accompanying code) some time ago. Some people liked it as an explainer to transducers: https://srfi.schemers.org/srfi-171/srfi-171.html
(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.