function | since v0.0-927 | clojure.core/pop | Edit |
(pop coll)
For a list, returns a new list without the first item.
For a vector, returns a new vector without the last item.
With vectors:
(pop [1 2 3])
;;=> [1 2]
(pop [1 2])
;;=> [1]
(pop [1])
;;=> []
(pop [])
;; Error: Can't pop empty vector
With lists:
(pop '(1 2 3))
;;=> (2 3)
(pop '(1 2))
;;=> (2)
(pop '(1))
;;=> ()
(pop '())
;; Error: Can't pop empty list
For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. Note - not the same as next/butlast.
(defn pop
[coll]
(when-not (nil? coll)
(-pop coll)))