This is my attempt to take Meikel's code and extend it to accept arbitrarily 
many collections as 'mapcat' does:

(defn lazy-mapcat [f & colls]
  (lazy-seq
   (when (every? seq colls)
     (concat (apply f (map first colls))
             (apply lazy-mapcat f (map rest colls))))))

user=> (->> (iterate f [0]) (lazy-mapcat identity) (take 1))
(0)
user=> (defn g [x y]
(println "computing x + y:" (+ x y))
[(+ x y)])
#'user/g
user=> (take 1 (mapcat g (range) (range)))
computing x + y: 0
computing x + y: 2
computing x + y: 4
computing x + y: 6
(0)
user=> (take 1 (lazy-mapcat g (range) (range)))
(computing x + y: 0
0)

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