On Wed, Nov 24, 2010 at 11:11 PM, Baishampayan Ghose <b.gh...@gmail.com> wrote: >> I just needed a function for every-nth element in a sequence.. I know it >> can be trivially implemented as .. >> (defn every-nth [n coll] >> (letfn [(evn [cn s] >> (when s >> (if (= cn 1) >> (lazy-seq (cons (first s) (evn n (next s)))) >> (evn (dec cn) (next s)))))] >> (evn n coll))) >> But I remember seeing inbuilt function .. can anybody help me find it? > > take-nth should do the job - > http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/take-nth
And it can be even more trivially implemented as (map first (partition n coll)). :) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en