1.2.0 permalink Arrow_down_16x16
  • (conj coll & xs)
Returns a new collection resulting from adding all xs to coll.

5 Examples top

  • ; Adds a single element to a vector (note with vectors, item is added to the end)
    
    (conj [:a :b :c] :d)
    
    => [:a :b :c :d]
  • ; Adds a variable number of elements to a vector ('& xs' in the function definition means to accept a variable number of parameters).  Note with vectors, item is added to the end
    
    (conj [:a :b :c] :d :e :f :g)
    
    => [:a :b :c :d :e :f :g]
  • ; Adds items to a list.  Note items are added to front of list and end up in reverse order because each individual item is added to the front of the list sequentially
    (conj '(1 2 3) :a :b :c)
    
    => (:c :b :a 1 2 3)
  • ; Add a list to an empty list.  Note the list remains intact and becomes a list within a list
    (conj () '(1 2 3 4))
    
    => ((1 2 3 4))
  • ; Adds a list to a vector.  Note list remains intact and is added at the end of the vector as a list within the vector.
    (conj [:a :b :c] '(1 2 3 4))
    
    => [:a :b :c (1 2 3 4)]
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/generic/collection.clj:42 top

(defmulti conj
  "Returns a new collection resulting from adding all xs to coll."
   {:arglists '([coll & xs])}
  (fn [coll & xs] (type coll)))
Vars in clojure.contrib.generic.collection/conj: conj defmulti fn type
Used in 0 other vars

Comments top

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