评论由:reborg_ 提出
垃圾输入垃圾输出(GIGO) 案例中,但 rem 也是负责的
用户=> (take-nth 2.5 (range 10))
(0 3 6 9)
用户=> (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)))))))