;; create lazy infinite seq of random ints
(def infi-seq (repeatedly #(rand-int 11)))
(take 5 infi-seq) ; => (8 2 9 9 5)
How can I get all values realized (8 2 9 9 2)
without knowing that the first five values have been realized?
This should do the trick:
(defn take-realized
[coll]
(if-not (instance? clojure.lang.IPending coll)
(cons (first coll) (take-realized (rest coll)))
(when (realized? coll)
(cons (first coll) (take-realized (rest coll))))))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With