Skip to content

Instantly share code, notes, and snippets.

@gtrak
Created February 6, 2013 22:55
Show Gist options
  • Save gtrak/4726660 to your computer and use it in GitHub Desktop.
Save gtrak/4726660 to your computer and use it in GitHub Desktop.
circular-lists.
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