I have some structures with nested lazy sequences which read from files. When I'm testing I would like to be able to wrap them in a recursive version of doall to make sure all the data is pulled from the files before the files get closed.
+2
A:
(defn doall-recur [s]
(if (seq? s)
(doall (map doall-recur
s))
s))
(use 'clojure.contrib.duck-streams)
(with-open [r1 (reader "test1.txt")
r2 (reader "test2.txt")]
(doall-recur (list (line-seq r2) (line-seq r1))))
Output:
(("This is test2.txt" "") ("This is test1.txt" ""))
alanlcode
2009-08-02 06:43:24