你好,
我听说如果之前在语言中包含转换器,它们会被用作所有序列懒操作的构建块。由于后来才添加,所以需要稍微修改代码以使用转换器。我想知道为什么不使用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 []))