评论人:reborg_
GIGO案例,但rem也有责任
user=> (take-nth 2.5 (range 10))
(0 3 6 9)
user=> (sequence (take-nth 2.5) (range 10))
(0 5)
Steve(CLJ-1665-faster-take-nth-transducer-without-rem.patch)的补丁缺少一个cast到int来解决这个问题
(defn take-nth [n]
(fn [rf]
(let [n (int n)
iv (volatile! 1)]
(fn
([] (rf))
([result] (rf result))
([result input]
(let [i (vswap! iv dec)]
(if (zero? i)
(do (vreset! iv n)
(rf result input))
result)))))))