clojure.core/take-nth¶
Returns a lazy seq of every nth item in coll. Returns a stateful transducer when no collection is provided.
Examples¶
Note by Dimagog¶
(take-nth 0 (range 10)) will loop forever.
Note by miner¶
(take-nth 0 coll) will return an infinite sequence repeating for first item from coll. A negative N is treated the same as 0.
Note by reborg¶
;; In case you are searching for it, drop-nth is not in core.
(defn drop-nth [n coll]
(lazy-seq
(when-let [s (seq coll)]
(concat (take (dec n) (rest s))
(drop-nth n (drop n s))))))
(drop-nth 3 (range 10))
;; (1 2 4 5 7 8)
;; or alternatively: (keep-indexed #(when-not (zero? (rem %1 n)) %2) coll)
See also¶
Content from the matching ClojureDocs page, with authors credited on each contribution.