Created
February 18, 2015 20:57
-
-
Save tbl3rd/69358a0db79cd5c2e610 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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