(take 11 (mapcat #(repeat % %) (range)))
;=> (1 2 2 3 3 3 4 4 4 4 5)
The functions map
, concat
(and combination mapcat
), as well as repeat
and range
are all lazy.
List comprehension, for
, is also lazy
(take 11 (apply concat (for [x (range)] (repeat x x))))
;=> (1 2 2 3 3 3 4 4 4 4 5)