How to convert lazy sequence to non-lazy in Clojure

前端 未结 5 1126
陌清茗
陌清茗 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:33

    This Rich guy seems to know his clojure and is absolutely right.
    Buth I think this code-snippet, using your example, might be a useful complement to this question :

    => (realized? (take 3 (repeatedly rand))) 
    false
    => (realized? (doall (take 3 (repeatedly rand)))) 
    true
    

    Indeed type has not changed but realization has

提交回复
热议问题