You're viewing version 1.2.0 of join. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (join coll)
  • (join separator [x & more])
Returns a string of all elements in coll, separated by
an optional separator. Like Perl's join.

2 Examples top

  • user=> (clojure.string/join ", " [1 2 3])
    "1, 2, 3"
    
  • ;; 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
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/string.clj:130 top

(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)))))
Vars in clojure.string/join: -> apply defn first loop next str
Used in 0 other vars

Comments top

No comments for join. Log in to add a comment.