Lazier than lazy
If you can’t put off what you have to do, ask someone else to do it for you.
(defn off
"Computes a lazy-seq in another (dedicated) thread."
[s]
(let [ex (. java.util.concurrent.Executors newSingleThreadExecutor)]
((fn this [s]
(if s
(let [future-rest (java.util.concurrent.FutureTask. #(rest s))]
(.execute ex future-rest)
(lazy-cons (first s) (this (.get future-rest))))
(.shutdown ex))) s)))