Created
February 6, 2013 22:55
-
-
Save gtrak/4726660 to your computer and use it in GitHub Desktop.
circular-lists.
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
user=> (take 6 (cycle [1 2 3])) | |
(1 2 3 1 2 3) | |
user=> (source cycle) | |
(defn cycle | |
"Returns a lazy (infinite!) sequence of repetitions of the items in coll." | |
{:added "1.0"} | |
[coll] (lazy-seq | |
(when-let [s (seq coll)] | |
(concat s (cycle s))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment