4 ms·
If I understand you correctly, transduces transform something like (map fn1 (map fn2 (map fn3 collection))) into (map (fn [x] (fn1 (fn2 (fn3 x)))) collection
by vaylian 3y ago
If I understand you correctly, transduces transform something like
(map fn1 (map fn2 (map fn3 collection)))
into
(map (fn [x] (fn1 (fn2 (fn3 x)))) collection); Is that correct?
More idiomatic clojure:
(map (comp fn1 fn2 fn3) collection)
- casion 3y agoYou have the idea, yes.
- thom 3y agoIt’s the mapping itself that can be composed with transducers. Where before you had pipelines of map/filter/whatever, now you have a single function representing the sequence operations, which can be used for any kind of sequence (a list in memory, or items coming in over a channel or message queue) item by item.
- sundarurfriend 3y agoThat sort of reminds of broadcast fusion [1] in Julia. Funnily enough, Julia is where I came across the term transducers too, via the Transducers.jl package [2]. The article and the comments here now make me wonder what the difference is, between broadcast fusion and transducers. [1] https://julialang.org/blog/2017/01/moredots/ https://julialang.org/blog/2017/01/moredots/ [2] https://github.com/JuliaFolds2/Transducers.jl/ https://github.com/JuliaFolds2/Transducers.jl/
- roguas 3y agoGenerally, yes, but I also think the fn1,fn2,fn3 can happen independently (which is why its powerful). So items of collection may be at different steps.