Hi,
I heard that if transducers were included before in the language, they would have been used as the building blocks of all sequence lazy operations. Since they were added later, you need to adapt your code a bit to use transducers. And I was wondering why using eduction
is not an option? I'm trying to understand the scenarios in which it's not a performance advantage to define the sequence lazy operations like this (of course assuming the same behaviour):
(defn map
([f] ;; the standard transducer definition
,,,)
([f coll]
(eduction (map f) coll))
I'm trying to understand given the assumption (which might be an erroneous assumption) that
(->> (range 5000000)
(eduction (map inc))
(eduction (filter odd?))
(eduction (map dec))
(eduction (filter even?))
(eduction (map (fn [n] (+ 3 n))))
(eduction (filter odd?))
(eduction (map inc))
(eduction (filter odd?))
(eduction (map dec))
(eduction (filter even?))
(eduction (map (fn [n] (+ 3 n))))
(eduction (filter odd?))
(into []))
is the same as
(->> (range 5000000)
(map inc)
(filter odd?)
(map dec)
(filter even?)
(map (fn [n] (+ 3 n)))
(filter odd?)
(map inc)
(filter odd?)
(map dec)
(filter even?)
(map (fn [n] (+ 3 n)))
(filter odd?)
(into []))