drop-last

added
1.0

ns
clojure.core

type
function

(drop-last s) (drop-last n s)

Return a lazy sequence of all but the last n (default 1) items in coll

                
(drop-last [1 2 3 4])
;=> (1 2 3) 

(drop-last -1 [1 2 3 4])
;=> (1 2 3 4) 

(drop-last 0 [1 2 3 4])
;=> (1 2 3 4) 

(drop-last 5 [1 2 3 4])
;=> ()

;; works differently with any seq.
;; but with some the last items become ambiguous.
(drop-last 2 (vector 1 2 3 4))
;=> (1 2)
(drop-last 2 (list 1 2 3 4 ))
;=> (1 2)
(drop-last 2 {:a 1 :b 2 :c 3 :d 4})
;=> ([:a 1] [:b 2])