Skip to content

Instantly share code, notes, and snippets.

@tbl3rd
Created February 18, 2015 20:57
Show Gist options
  • Save tbl3rd/69358a0db79cd5c2e610 to your computer and use it in GitHub Desktop.
Save tbl3rd/69358a0db79cd5c2e610 to your computer and use it in GitHub Desktop.
(defn drop-nth-tbl3rd
"coll with every nth element removed"
[n coll]
(letfn [(drop-when [coll drops]
(lazy-seq
(when-let [s (seq coll)]
(let [more (drop-when (rest s) (rest drops))]
(if (first drops) more (cons (first s) more))))))]
(drop-when coll (rest (cycle (cons true (repeat (dec n) false)))))))
(defn drop-nth-tbc++-Westerhof
[n coll]
(keep-indexed
(fn [i v] (if (zero? (mod i n)) nil v))
coll))
(defn drop-nth-Cecil-Jones
[n coll]
(lazy-seq
(when-let [s (seq coll)]
(concat (take (dec n) s) (drop-nth n (drop n s))))))
(defn drop-nth-Fluid-Dynamics
[n coll]
(->> (seq coll)
(cons ::sentinel)
(partition n n nil)
(map next)
(mapcat identity)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment