There is a lazy version of the fill function:
(defn lazy-pad "Returns a lazy sequence which pads sequence with pad-value." [sequence pad-value] (if (empty? sequence) (repeat pad-value) (lazy-seq (cons (first sequence) (lazy-pad (rest sequence) pad-value)))))
You can use it as a regular endless lazy collection:
(take 5 (lazy-pad [1 2 3] :pad)) => (1 2 3 :pad :pad)
IMO this is more elegant. You can also use it with other functions that expect a lazy sequence that doesn't work if you need to specify an upfront length:
(partition 2 (interleave [1 2 3 4] (lazy-pad [:a] :pad))) => ((1 :a) (2 :pad) (3 :pad) (4 :pad))
source share