I have a map that I want to 'expand' into an infinite sequence in the following manner:
{0 'zero 3 'three 10 'ten}
=>
('zero 'zero 'zero 'three 'three 'three 'three 'three 'three 'three 'ten 'ten 'ten ...)
the indexes of the map indicating the index of the sequence where the value should change
The following code works, but it does not please me. Can this be written in a smarter way?
(defn expand-map
[m]
(letfn [(em
[last-value indexes]
(let [value (m (first indexes))]
(if value
(lazy-seq (cons value (em value (rest indexes))))
(lazy-seq (cons last-value (em last-value (rest indexes)))))))]
(em 'zero (iterate inc 0))))
(take 20 (expand-map {0 'zero 3 'three 10 'ten}))