Returns a string of all elements in coll, separated by
an optional separator. Like Perl's join.
;; 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, separated by
an optional separator. Like Perl's join."
{:added "1.2"}
([coll]
(apply str coll))
([separator [x & more]]
(loop [sb (StringBuilder. (str x))
more more
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.