【发布时间】:2009-08-01 18:03:40
【问题描述】:
我有一些结构具有从文件中读取的嵌套惰性序列。当我测试时,我希望能够将它们包装在 doall 的递归版本中,以确保在文件关闭之前从文件中提取所有数据。
【问题讨论】:
我有一些结构具有从文件中读取的嵌套惰性序列。当我测试时,我希望能够将它们包装在 doall 的递归版本中,以确保在文件关闭之前从文件中提取所有数据。
【问题讨论】:
(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))))
输出:
(("This is test2.txt" "") ("This is test1.txt" ""))
【讨论】:
(defn doall* [s] (dorun (tree-seq seq? seq s)) s)
【讨论】:
s 需要是doall* 将适用的代码的引用版本?
这在单元测试中对我有用
(use 'clojure.walk)
(postwalk identity nested-lazy-thing)
【讨论】: