function | since v0.0-927 | clojure.core/cons | Edit |
(cons x coll)
Returns a new sequence where x
is the first element and coll
is the rest.
(cons 1 (list 1 2 3))
;;=> (1 1 2 3)
(cons 1 [1 2 3])
;;=> (1 1 2 3)
(cons 1 nil)
;;=> (1)
(cons nil nil)
;;=> (nil)
Returns a new seq where x is the first element and coll is the rest.
(defn cons
[x coll]
(cond
(nil? coll) (List. nil x nil 1 nil)
(implements? ISeq coll) (Cons. nil x coll nil)
:default (Cons. nil x (seq coll) nil)))