Rich Hickey - Inside Transducers
Why Stack Overflow recommends it
Stack Overflow users link it as the authoritative source from Clojure's author when answering questions about transducer semantics, stateful transducers, reduced, and core.async pipelines.
Recommended by 1 people across 1 different months, 2015 to 2023.
What it is
A conference talk from Clojure/conj 2014 in which Rich Hickey, the creator of Clojure, explains how transducers work internally: the step and completion arities, early termination with reduced, stateful transducers, and transducible contexts. It also touches on the awkward semantics of reduce without an initial value.
Cited in 1 Wikipedia article, including Clojure.
What people said
Recommends Arthur Ulfeldt · 2015-10 · Stack Overflow · on “What does calling map with one argument do in Clojure?”
calling map with a single argument in clojure 1.7+ returns a transducer [LINK] that can be composed with other transducers and eventually a call to into or some other transducing thing. I recommend this video first [LINK] , and then this one [this video] This allows you to use all the clojure sequence abstractions without the computer spending a lot of time building intermediate sequences. In clojure less than 1.7 it will throw an arity exception
Cites Arthur Ulfeldt · 2015-02 · Stack Overflow · on “Add delay in clojure.core.async”
There are plans to offer this feature [this video] with channels, though for now you can check for the presence of something on a channel with: (alts!! [my-chan] :default :nothing-immediately-in-chan) by iterating that you can drain a channel without blocking. PS: extra thanks to tbaldridge and julianlevis on #clojure for helping with this one
Cites Michał Marczyk · 2016-03 · Stack Overflow · on “What is the purpose of clojure.core.reducers/reduce?”
Two possible reasons: It has different – better! – semantics than clojure.core/reduce in the initless sequential case. During his 2014 Conj presentation Rich Hickey asked "who knows what the semantics of reduce are when you call it with a collection and no initial value?" – follow this link for the exact spot in the presentation [this video] – and then described the said semantics as "a ridiculous, complex rule" and "one of the worst things [he] ever copied from Common Lisp" – cf. Common Lisp's reduce contract [LINK] . The presentation was about transducers and the context of the remark was a discussion of transduce , which has a superior, simpler contract; r/reduce does as well. Even without con
Cites Alan Thompson · 2018-02 · Stack Overflow · on “What is a foldable collection in Clojure?”
The answer is there in the docs, if not quite as clear as it could be: Additionally, some collections (persistent vectors and maps) are foldable. The fold operation on a reducer executes the reduction in parallel... The idea is that, with modern hardware, a "reduction" operation like summing all elements of a vector can be done in parallel. For example, if summing all elements of a 400K length vector, we could break them up into 4 groups of 100K chunks, sum those in parallel, then combine the 4 subtotals into the final answer. This would be approximately 4x faster than using only a single thread (single cpu core). Reducers live in the clojure.core.reducers namespace. Assume we define aliases
Cites OlegTheCat · 2018-03 · Stack Overflow · on “core.async with partition-by stateful transducer not keeping state?”
This particular case was briefly highlighted [this video] by Rich Hickey in his talk: you cannot use pipeline with stateful transducers, basically because of pipeline 's parallel nature.
Cites user2609980 · 2022-08 · Stack Overflow · on “Is my understanding of transducers correct?”
@Bergi see Rich Hickey's comment on in Inside Transducers (2014) [this video] : "It's your job as a transducible context to apply the transducer to your step function. That should never be a user space activity. That transduced step function is now potentially a stateful thing, which means you do not want more than one person to have that. You should never hand a transduced reducing function around, which means all transducible contexts should accept a transducer and, inside them, you call the transducer on the step function and make the transformed step function."
Cites drRobertz · 2023-04 · Stack Overflow · on “Transducers: What should the completion arity do if the nested step arity has returned reduced?”
A stateful transducer is expected to flush its state by calling the "step" arity (i.e. [([result input] ) ) as many times as needed, before calling the "complete" arity (i.e. ([result] ) ). My question is how early termination (with reduced ) is to be handled here. On [LINK] it says In the completion step, a transducer with reduction state should flush state prior to calling the nested transformer’s completion function, unless it has previously seen a reduced value from the nested step in which case pending state should be discarded. but what does "has previously seen" mean? There are three possible interpretations of the above quote: If the "step" arity of the nested transformer has returne