On 29 March 2012 21:41, Cedric Greevey <cgree...@gmail.com> wrote: > > On Thu, Mar 29, 2012 at 4:18 PM, David Jagoe <davidja...@gmail.com> wrote:
> > Given a sequence like this: [1 2 1 2 1 1 2 1 2 2 2] > > > > partition it to get this: [(1 2) (1 2) (1) (1 2) (1 2) (2) (2)] > >! > > (defn partition-distinct [s] > (lazy-seq > (loop [seen #{} s (seq s) part []] > (if s > (let [[f & r] s] > (if (seen f) > (cons (seq part) (partition-distinct s)) > (recur (conj seen f) r (conj part f)))) > (if-let [part (seq part)] > (list part)))))) > Thanks! I had a nasty feeling that it could be done in a one-liner using partition-by or something similar. But of course you need to be able to look at previous elements... -- 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