On Dec 3, 2:10 pm, ataggart <[email protected]> wrote:
> There's take-nth in core, but no drop-nth (which sounds like what you
> need), so I wrote it:
>
> (defn drop-nth [n coll]
> (lazy-seq
> (when-let [s (seq coll)]
> (concat (take n s) (drop-nth n (next (drop n s)))))))
>
> So, in your example:
>
> (vec (drop-nth 2 [2 4 5 8 6 4]))
>
Just realized I wrote that zero-based, but take-nth is 1-based.
Fixed:
(defn drop-nth [n coll]
(lazy-seq
(when-let [s (seq coll)]
(concat (take (dec n) s) (drop-nth n (drop n s))))))
Note the results aren't mutually exclusive to take-nth since both
"take" the first element (which seems reasonable).
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en