If you were feeling so inclined, you could structure this as a lazy sequence
(like 'partition' does)
(defn lazy-break
[coll]
(letfn [(break-paired [pairs]
(lazy-seq
(when-let [s (seq pairs)]
(let [p (doall (take-while (fn [[a b]] (= (inc a) b)) pairs))
cutpoint (count p)]
(cons (concat p [(nth pairs cutpoint)])
(break-paired (drop (inc cutpoint) pairs)))))))]
(map #(map first %) (break-paired (map vector coll (rest coll))))))
user> (take 2 (lazy-break (concat (range 4) (range 3) (range))))
((0 1 2 3) (0 1 2))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en