The Clojure function
(reductions + 0 (cycle [1 1 -1]))
produces a sequence [0 1 2 1 2 3 2 3 4 3 4 5 ...]. Unfortunately, this sequence isn't lazy.
As cycle
and reductions
are both documented as returning lazy sequences, I expected this combination of those functions to return a lazy sequence as well. Why doesn't it and how can I fix it to return the sequence lazily?
A more complex example that shows the same problem:
(reductions (fn [x f] (f x)) 0 (cycle [inc inc dec]))
(I show this, because this is the kind of version I would like to have working in the end, in case that makes any difference)