cycle

clojure.core

  • (cycle coll)
Returns a lazy (infinite!) sequence of repetitions of the items in coll.

1 Example top

  • user=> (take 5 (cycle ["a" "b"]))
    ("a" "b" "a" "b" "a")
    
    user=> (take 10 (cycle (range 0 3)))
    (0 1 2 0 1 2 0 1 2 0)
    
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2556 top

(defn cycle
  "Returns a lazy (infinite!) sequence of repetitions of the items in coll."
  {:added "1.0"
   :static true}
  [coll] (lazy-seq 
          (when-let [s (seq coll)] 
              (concat s (cycle s)))))
Vars in clojure.core/cycle:
Used in 0 other vars

Comments top

No comments for cycle. Log in to add a comment.