Does Clojure get your head around?
I have a very large lazy sequence and I would like to convert it to a set. I know that the number of individual items in a sequence is small, so I can easily set the set to memory. However, I may not be able to fit the entire lazy segment into memory. I just want to do it (into #{} my-lazy-seq)
, but it occurred to me that depending on how it is implemented into
, this might dump the entire seq into memory at once.
Will it be into
held at the beginning of the sequence when it is running?
source to share
I don't see an increase in the use of this app (takes a minute or so)
user=> (into #{} (take 1e8 (cycle [:foo :bar])))
#{:bar :foo}
A more accurate proof would be to check the source for into
, and we see this as just a fancy call reduce
:
(defn into
([to from]
;...
(reduce conj to from)))
If reduce
rests on the head, it into
does. But I don't think it reduce
does.
source to share