ClojureDocs

Nav

Namespaces

repeat

clojure.core

Available since 1.0 (source)
  • (repeat x)
  • (repeat n x)
Returns a lazy (infinite!, or length n if supplied) sequence of xs.
2 Examples
user=> (take 5 (repeat "x"))
("x" "x" "x" "x" "x")

;; which is the same as:
user=> (repeat 5 "x")
("x" "x" "x" "x" "x")

;; It should be noted that repeat simply repeats the value n number of times.
;; If you wish to execute a function to calculate the value each time you 
;; probably want the repeatedly function.

(defn tally [n]
  (apply str
         (concat
           (repeat (quot n 5) "卌")
           (repeat (mod n 5) "|"))))

(map tally (range 1 11))
;; ("|" "||" "|||" "||||" "卌" "卌|" "卌||" "卌|||" "卌||||" "卌卌")
See Also

Takes a function of no args, presumably with side effects, and returns an infinite (or length n if...

Added by zk

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

Added by alimoeeny

Returns a function that takes any number of arguments and returns x.

Added by TimMc

bindings => name n Repeatedly executes body (presumably for side-effects) with name bound to in...

Added by kumarshantanu
0 Notes
No notes for repeat