I would use reductions(i.e. Haskell's scanl) given my understanding that
clojure sequence is just as lazy as Haskell.

(rest (map first (reductions (fn [ [v a b] x ] (if (= a x) [b nil b] [x a
b]))
[nil 2 3] '(1 1 2 2 3 4))))

I use nil here as 'something that would not appear in the list', I am sure
there are better marker if 'nil' is a valid value.

If there is a foldr in clojure, it is also possible to short circuit the
rest of comparison once the first is found.

The other possibility is using 'unfold', I am not quite familiar with
clojure's sequence functions. There may be one already, using some other
names.

-- 
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

Reply via email to