HI,

Am 10.11.2010 um 21:28 schrieb David Jacobs:

> That is, if I have (1 2 3 4 4 5 5 5 5 5 6 9 12 12), I want to get back
> the sequence (4 4 5 5 5 5 5 12 12).

Low-level solution using lazy-seq. As lazy as possible:

(defn ties
  [coll]
  (let [step (fn step [seen s]
               (lazy-seq
                 (loop [s (seq s)]
                   (when-first [fst s]
                     (if (contains? seen fst)
                       (cons fst (step seen (rest s)))
                       (when-let [sn (next s)]
                         (let [snd (first sn)]
                           (if (= fst snd)
                             (cons fst (cons snd (step (conj seen fst)
                                                       (rest sn))))
                             (recur sn)))))))))]
    (step #{} coll)))

Sincerely
Meikel

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