Search code examples
clojure

How to repeat string n times in idiomatic clojure way?


In Ruby, "str" * 3 will give you "strstrstr". In Clojure, the closest I can think of is (map (fn [n] "str") (range 3)) Is there a more idiomatic way of doing it?


Solution

  • How about this?

    (apply str (repeat 3 "str"))
    

    Or just

    (repeat 3 "str")
    

    if you want a sequence instead of a string.