function | since v0.0-927 | clojure.core/take-nth | Edit |
(take-nth n)
(take-nth n coll)
Returns a lazy seq of every n
th item in coll
.
Returns a stateful transducer when no collection is provided.
Returns a lazy seq of every nth item in coll. Returns a stateful transducer when no collection is provided.
(defn take-nth
([n]
{:pre [(number? n)]}
(fn [rf]
(let [ia (volatile! -1)]
(fn
([] (rf))
([result] (rf result))
([result input]
(let [i (vswap! ia inc)]
(if (zero? (rem i n))
(rf result input)
result)))))))
([n coll]
{:pre [(number? n)]}
(lazy-seq
(when-let [s (seq coll)]
(cons (first s) (take-nth n (drop n s)))))))