Skip to content

clojure.core/butlast

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 4 Runnable: 4
([coll])

Return a seq of all but the last item in coll, in linear time

Examples

by dpritchett on
by boxie on
by reborg on
by Crowbrammer on

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


Content from the matching ClojureDocs page, with authors credited on each contribution.