你好,
我听说如果转换器在语言中先加入,它们将作为所有序列懒惰操作的构建块。由于它们后来才被添加,您需要适当地修改代码以使用转换器。我想知道为什么不使用eduction
呢?我正在尝试理解不定义这样的序列懒惰操作(当然假设行为相同)的场景。
(defn map
([f] ;; the standard transducer definition
,,,)
([f coll]
(eduction (map f) coll))
我正在尝试理解一个假定(这可能是错误的假设):
(->> (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 []))
等同于
(->> (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 []))