How to repeat string n times in idiomatic clojure way?

前端 未结 7 2204
无人及你
无人及你 2020-12-15 16:13

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 idioma

相关标签:
7条回答
  • 2020-12-15 16:58

    You could also use the repeat function from clojure.contrib.string. If you add this to your namespace using require such as

    (ns myns.core (:require [clojure.contrib.string :as str]))
    

    then

    (str/repeat 3 "hello")
    

    will give you

    "hellohellohello"
    
    0 讨论(0)
提交回复
热议问题