Thanks.  That's helps me think about when/how to use lazy-seq

On Sep 28, 2:00 pm, Nathan Sorenson <n...@sfu.ca> wrote:
> 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 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