views:

158

answers:

2

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
+2  A: 
(defn doall* [s] (dorun (tree-seq seq? seq s)) s)
cgrand