Returns a string of all elements in coll, as returned by (seq coll),
separated by an optional separator.
;; Splits a string on space character and joins
;; the resulting collection with a line feed character
(use '[clojure.string :only (join split)])
user=> (println
(join "\n"
(split "The Quick Brown Fox" #"\s")))
The
Quick
Brown
Fox
nil
(defn ^String join
"Returns a string of all elements in coll, as returned by (seq coll),
separated by an optional separator."
{:added "1.2"}
([coll]
(apply str coll))
([separator coll]
(loop [sb (StringBuilder. (str (first coll)))
more (next coll)
sep (str separator)]
(if more
(recur (-> sb (.append sep) (.append (str (first more))))
(next more)
sep)
(str sb)))))
Comments top
No comments for join. Log in to add a comment.