take-nth should do the job -
http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/take-nth
Regards,
BG
--
Baishampayan Ghose
b.ghose at gmail.com
And it can be even more trivially implemented as (map first (partition
n coll)). :)
(map first (partition 1 n coll))
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
Yes, that seems to work too, but it's also two characters longer. :)
OTOH,
(mapcat identity (partition 1 n coll))
(apply concat (partition 1 n coll))
(keep-indexed (fn [i x] (if (= 0 (rem i n)) x)) coll)
(map first (partition-all n coll))
(mapcat identity (partition-all n coll))
(apply concat (partition-all n coll))
and the winner is:
(flatten (partition 1 n coll))
Only 30 characters. :)
Eh. This is weird. It seems that (partition n coll) drops the last
part of coll if it's not a multiple of n in size; e.g. (partition 3 [1
2 3 4 5]) yields ((1 2 3)) and not ((1 2 3) (4 5)). (partition n n []
coll) does do that though.