How to convert lazy sequence to non-lazy in Clojure

This is to some degree a question of taxonomy. a lazy sequence is just one type of sequence as is a list, vector or map. So the answer is of course "it depends on what type of non lazy sequence you want to get:
Take your pick from:

  • an ex-lazy (fully evaluated) lazy sequence (doall ... )
  • a list for sequential access (apply list (my-lazy-seq)) OR (into () ...)
  • a vector for later random access (vec (my-lazy-seq))
  • a map or a set if you have some special purpose.

You can have whatever type of sequence most suites your needs.


doall is all you need. Just because the seq has type LazySeq doesn't mean it has pending evaluation. Lazy seqs cache their results, so all you need to do is walk the lazy seq once (as doall does) in order to force it all, and thus render it non-lazy. seq does not force the entire collection to be evaluated.