Clojure: Transducers
by tosh on 4/19/2026, 10:56:20 AM
https://clojure.org/reference/transducers
Comments
by: drob518
Transducers work even better with a Clojure library called Injest. It has macros similar to the standard Clojure threading macros except Injest’s macros will recognize when you’re using transducers and automatically compose them correctly. You can even mix and match transducers and non-transducer functions and Injest will do its best to optimize the sequence of operations. And wait, there’s more! Injest has a parallelizing macro that will use transducers with the Clojure reducers library for simple and easy use of all your cores. Get it here: <a href="https://github.com/johnmn3/injest" rel="nofollow">https://github.com/johnmn3/injest</a><p>Note: I’m not the author of Injest, just a satisfied programmer.
4/21/2026, 5:14:34 PM
by: adityaathalye
May I offer a little code riff slicing FizzBuzz using transducers, as one would do in practice, in real code (as in not a screening interview round).<p><i>Demo One: Computation and Output format pulled apart</i><p><pre><code> (def natural-nums (rest (range))) (def fizz-buzz-xform (comp (map basic-buzz) (take 100))) ;; early termination (transduce fizz-buzz-xform ;; calculate each step conj ;; and use this output method [] ;; to pour output into this data structure natural-nums) (transduce fizz-buzz-xform ;; calculate each step str ;; and use this output method "" ;; to catenate output into this string natural-nums) ;; given this input (defn suffix-comma [s] (str s ",")) (transduce (comp fizz-buzz-xform (map suffix-comma)) ;; calculate each step str ;; and use this output method "" ;; to catenate output into this string natural-nums) ;; given this input </code></pre> Demos two and three for your further entertainment are here: <a href="https://www.evalapply.org/posts/n-ways-to-fizzbuzz-in-clojure/#transducery-buzz" rel="nofollow">https://www.evalapply.org/posts/n-ways-to-fizzbuzz-in-clojur...</a><p>(edit: fix formatting, and kill dangling paren)
4/21/2026, 4:35:38 PM
by: bjoli
I made srfi-171 [0], transducers for scheme. If you have any questions about them in general I can probably answer them. My version is pretty similar to the clojure version judging by the talks Rich Hickey gave on them.<p>I know a lot of people find them confusing.<p>0: <a href="https://srfi.schemers.org/srfi-171/srfi-171.html" rel="nofollow">https://srfi.schemers.org/srfi-171/srfi-171.html</a>
4/21/2026, 4:13:14 PM
by: pjmlp
Nowadays you can make use of some transducers ideas via gatherers in Java, however it isn't as straightforward as in plain Clojure.
4/21/2026, 5:18:44 PM
by: thih9
From (2016) at least.<p><a href="https://web.archive.org/web/20161219045343/https://clojure.org/reference/transducers" rel="nofollow">https://web.archive.org/web/20161219045343/https://clojure.o...</a>
4/21/2026, 4:16:25 PM
by: eduction
The key insight behind transducers is that a ton of performance is lost not to bad algorithms or slow interpreters but to copying things around needlessly in memory, specifically through intermediate collections.<p>While the mechanics of transducers are interesting the bottom line is they allow you to fuse functions and basic conditional logic together in such a way that you transform a collection exactly once instead of n times, meaning new allocation happens only once. Once you start using them you begin to see intermediate collections everywhere.<p>Of course, in any language you can theoretically do everything in one hyperoptimized loop; transducers get you this loop without much of a compromise on keeping your program broken into simple, composable parts where intent is very clear. In fact your code ends up looking nearly identical (especially once you learn about eductions… cough).
4/21/2026, 4:47:35 PM
by: mannycalavera42
transducers and async flow are :chefkiss
4/21/2026, 3:47:14 PM
by: faraway9911
[dead]
4/21/2026, 4:44:16 PM