clojure-dev

dgr 2026-05-20T16:15:32.020439Z

I’m working on testing concat and lazy-cat for #clojure-test-suite. After reading through the doc strings for both, I’m struggling to understand in which situations I’d use lazy-cat instead of concat. The doc string for lazy-cat says: (lazy-cat xs ys zs) === (concat (lazy-seq xs) (lazy-seq ys) (lazy-seq zs)). Given that concat returns a lazy-seq , as do most of the sequence functions that are likely to form inputs to lazy-cat, under what circumstances is lazy-cat providing me more desirable laziness than I already have with concat? And that’s doubly a question with chunking being part of the equation, since any underlying chunking will undo some of the laziness. Is this mostly a historical artifact of Clojure’s development, or are there real situations today (Clojure 1.12) where lazy-cat is particularly required?

dpsutton 2026-05-20T16:20:33.750009Z

there’s a usage in the tests for for that is interesting:

(defn only
  "Returns a lazy seq of increasing ints starting at 0.  Trying to get
  the nth+1 value of the seq throws an exception.  This is meant to
  help detecting over-eagerness in lazy seq consumers."
  [n]
  (lazy-cat (range n)
            (throw (Exception. "consumer went too far in lazy seq"))))

👍 1
dgr 2026-05-20T16:33:25.292509Z

Thanks. I suspect that test was written a while ago. range is chunked, now, so wrapping it in a lazy-seq doesn’t do much other than put off any initial chunking, which I suspect is already deferred (I’d have to go through the chunking implementation). You’d get the same thing, I think, with (concat (range n) (lazy-seq (throw (Exception. …)))). Based on this, it doesn’t seem like lazy-cat is adding much to the core API. That’s why I’m suspecting that it’s a historical artifact that might not provide much value in modern Clojure.

tomd 2026-06-01T08:19:44.371459Z

I’ve always thought of it for “building a lazy seq out of non-lazy collections with different creation costs” as Renzo noted https://clojuredocs.org/clojure.core/lazy-cat#example-5aa01b54e4b0316c0f44f910.