Created
June 9, 2012 00:05
-
-
Save ralfonso/2898759 to your computer and use it in GitHub Desktop.
clojure cycling generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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