Skip to content

Instantly share code, notes, and snippets.

@ralfonso
Created June 9, 2012 00:05
Show Gist options
  • Save ralfonso/2898759 to your computer and use it in GitHub Desktop.
Save ralfonso/2898759 to your computer and use it in GitHub Desktop.
clojure cycling generator
(defn cycling-generator
[items]
(let [items-cycle (cycle items)
remaining (atom items-cycle)]
(fn []
(let [cur (first @remaining)]
(dosync
(swap! remaining rest))
cur))))
-------------
(def gen [1 2 3 4 5 6 7])
(gen)
1
(gen)
2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment