In the answer to this question the responder uses the function reduced
(defn state [t]
(reduce (fn [[s1 t1] [s2 t2]]
(if (>= t1 t) (**reduced** s1) [s2 (+ t1 t2)]))
(thomsons-lamp)))
I looked at the doc and source and can't fully grok it.
(defn reduced
"Wraps x in a way such that a reduce will terminate with the value x"
{:added "1.5"}
[x]
(clojure.lang.Reduced. x))
In the example above I think (reduced s1)
is supposed to end the reduction and return s1.
Is using reduce + reduced equivalent to hypothetical reduce-while or reduce-until functions if either existed?