Tutorial by Examples

(let [xf (comp (map inc) (filter even?))] (transduce xf + [1 2 3 4 5 6 7 8 9 10])) ;; => 30 This example creates a transducer assigned to the local xf and uses transduce to apply it to some data. The transducer add's one to each of it's inputs and only returns the ...
(def xf (filter keyword?)) Apply to a collection, returning a sequence: (sequence xf [:a 1 2 :b :c]) ;; => (:a :b :c) Apply to a collection, reducing the resulting collection with another function: (transduce xf str [:a 1 2 :b :c]) ;; => ":a:b:c" Apply to a collection, and...
So the most used functions on Clojure map and filter have been modified to return transducers (composable algorithmic transformations), if not called with a collection. That means: (map inc) returns a transducer and so does (filter odd?) The advantage: the functions can be composed into a single f...

Page 1 of 1