function | since v0.0-927 | clojure.core/conj | Edit |
(conj)
(conj coll)
(conj coll x)
(conj coll x & xs)
conj(oin)
Returns a new collection with the x
s "added" to coll
.
The "addition" may happen at different "places" depending on the collection type.
(conj nil item)
returns (item)
.
Append a vector:
(conj [1 2 3] 4)
;;=> [1 2 3 4]
Prepend a list:
(conj (list 1 2 3) 0)
;;=> (0 1 2 3)
Prepend a sequence:
(def x (range 1 4))
;;=> (1 2 3)
(conj x 0)
;;=> (0 1 2 3)
Add to set:
(conj #{"a" "b" "c"} "d")
;;=> #{"a" "b" "c" "d"}
conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). (conj coll) returns coll. (conj) returns []. The 'addition' may happen at different 'places' depending on the concrete type.
(defn conj
([] [])
([coll] coll)
([coll x]
(if-not (nil? coll)
(-conj coll x)
(list x)))
([coll x & xs]
(if xs
(recur (conj coll x) (first xs) (next xs))
(conj coll x))))