Returns a lazy seq representing the concatenation of the elements in the supplied colls.
user=> (concat [1 2] [3 4]) (1 2 3 4) user=> (into [] (concat [1 2] [3 4])) [1 2 3 4] user=> (concat [:a :b] nil [1 [2 3] 4]) (:a :b 1 [2 3] 4) => (concat [1] [2] '(3 4) [5 6 7] #{9 10 8}) (1 2 3 4 5 6 7 8 9 10) ;; The last three elements might appear in a different order.
(defn padding-right [s width pad] (apply str (take width (concat s (repeat pad))))) (padding-right "Clojure" 10 " ") ;; "Clojure "
;; beware! concat returns a lazy 'sequence'. (conj (concat [1 2] [3 4]) 5) ; doesn't return (1 2 3 4 5) ;;=>(5 1 2 3 4)
;; Here is a good article by Stuart Sierra in his "Clojure Dont's" series ;; on concat, and how using it in certain ways can lead to surprisingly large ;; stack usage: ;; https://stuartsierra.com/2015/04/26/clojure-donts-concat (first (reduce concat (map next-results (range 1 4000)))) ;; StackOverflowError clojure.core/seq (core.clj:133) (nth (iterate #(concat % [1 2 3]) [1 2 3]) 4000) ;; StackOverflowError clojure.core/seq (core.clj:133)
;; list 1 (def list1 (list 'let ['x 10])) ;; => #'user/list1 list1 ;; => (let [x 10]) ;; list 2 (def list2 (list '(println "x:" x) '(println "Bye!"))) ;; => #'user/list2 list2 ;; => ((println "x:" x) (println "Bye!")) ;; *** ;; concat all the elements of list1 & list2, and return a new list ;; In this case - let + [x 10] + (println "x:" x) + (println "Bye!") (concat list1 list2) ;; => (let [x 10] (println "x:" x) (println "Bye!")) (eval (concat list1 list2)) ;; => x: 10 ;; Bye! ;; nil ;; see also - quote
(concat [1 2 3] 4 5) ;; => (1Error printing return value (IllegalArgumentException) at clojure.lang.RT/seqFrom (RT.java:577). ;; Don't know how to create ISeq from: java.lang.Long (concat [1 2 3] [4 5]) ;; => (1 2 3 4 5)
conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). (co...
Returns a new coll consisting of to-coll with all of the items of from-coll conjoined. A transduce...
Expands to code which yields a lazy sequence of the concatenation of the supplied colls. Each col...
Yields the unevaluated form. See http://clojure.org/special_forms for more information.
Returns the result of applying concat to the result of applying map to f and colls. Thus function...
Returns a map with the keys mapped to the corresponding vals.
A transducer which concatenates the contents of each input, which must be a collection, into the r...
A high-performance combining fn that yields the catenation of the reduced values. The result is re...
concat