Not definitely, but you can always give a lambda with some condition!
(let [a (atom ["a" "b"])]
(defn f []
(let [r (first @a)]
(swap! a rest)
r)))
(f) ;; "a"
(f) ;; "b"
(f) ;; nil
In your particular case, it would be wise to have a function that generates a stateful function. So a complete example:
(defn maker [l]
(let [a (atom l)]
(fn []
(let [r (first @a)]
(swap! a rest)
r))))
(with-redefs [read-line (maker ["HI" "OK"])]
(do (println (read-line)) ;; -> "HI"
(println (read-line)))) ;; -> "OK"
source
share