clojure.core/butlast¶
Return a seq of all but the last item in coll, in linear time
Examples¶
Note by miner¶
When using a vector, pop is faster than butlast.
Note by huahaiy¶
pop will throw exception if the vector is empty, whereas butlast will return nil
Note by Crowbrammer¶
In my example, but-last is ~100 x slower than drop-last. butlast cannot remove multiple elements from the end, but drop-last can. butlast seems eager, and drop-last seems lazy. 'butlast' will return nil when empty, and drop-last will return '() when empty.
See also¶
- clojure.core/first (2)
- clojure.core/rest (6)
- clojure.core/last (2)
- clojure.core/next (2)
- clojure.core/drop-last (1)
- clojure.core/take-last (1)
- clojure.core/pop (2)
Content from the matching ClojureDocs page, with authors credited on each contribution.