Clojure의 재귀 (doall)
-
07-07-2019 - |
문제
파일에서 읽은 중첩 게으른 시퀀스가있는 구조가 있습니다. 테스트 할 때 모든 데이터가 파일에서 가져 오는지 확인하기 위해 재귀 버전의 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)
이것은 단위 테스트에서 저에게 효과가있었습니다
(use 'clojure.walk)
(postwalk identity nested-lazy-thing)
제휴하지 않습니다 StackOverflow