How to convert lazy sequence to non-lazy in Clojure

前端 未结 5 1142
陌清茗
陌清茗 2020-11-29 18:19

I tried the following in Clojure, expecting to have the class of a non-lazy sequence returned:

(.getClass (doall (take 3 (repeatedly rand))))
5条回答
  •  天命终不由人
    2020-11-29 18:31

    I stumbled on this this blog post about doall not being recursive. For that I found the first comment in the post did the trick. Something along the lines of:

    (use 'closure.walk)
    (postwalk identity nested-lazy-thing)
    

    I found this useful in a unit test where I wanted to force evaluation of some nested applications of map to force an error condition.

提交回复
热议问题