_评论者: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)的补丁仅缺少强转换为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)))))))