Recursive (doall) in clojure

I have some structures with nested lazy sequences that are read from files. When I test, I would like to be able to wrap them in a recursive version of doall so that all data is extracted from the files before closing the files.

+6
clojure lazy-evaluation
source share
3 answers
(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" "")) 
+5
source share
 (defn doall* [s] (dorun (tree-seq seq? seq s)) s) 
+5
source share

This worked for me in unit test

 (use 'clojure.walk) (postwalk identity nested-lazy-thing) 
0
source share

All Articles