Hacker News new | ask | show | jobs
by vaylian 1012 days 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)

4 comments

It’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.
That 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/ [2] https://github.com/JuliaFolds2/Transducers.jl/

Generally, 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.
You have the idea, yes.