Questions on lazy-seq.
I stumbled on below code from clojure essential reference book
(defn untangle [n xs] (letfn [(step [xs] (lazy-seq (cons (take-nth n xs) (step (rest xs)))))] (take n (step xs)))) (untangle 2 (interleave (range 3) (repeat 3 "."))) ;; ((0 1 2) ("." "." "."))
I understand if xs is an infinite sequence. It generates next element on demand.
But it’s a finite sequence. My question is how the lazy-seq knows when it terminates the step function.