liveBook · Manning

Drop-last

As explained in Clojure: The Essential Reference

drop-last is a Clojure function that returns a sequence with a specified number of elements removed from its end.

drop-last returns a sequence with a specified number of elements removed from the end. With one argument, it removes the final element; with two arguments, n controls how many elements are omitted. section 10.2

Key behavior:

  • Accepts a sequential collection and an optional numeric n; negative n behaves like zero. section 10.2
  • Returns a fully lazy sequence, but does not provide a transducer arity. section 10.2
  • Composes with sequence operations when the desired result is the input head without its tail. section 10.2

Lazy construction

Given a lazy sequence whose elements print when realized, (drop-last (xs)) produces a result without printing during construction. The returned sequence remains lazy until consumed.

How Clojure: The Essential Reference covers it

How deep it goes
Defines arities, numeric edge cases, laziness, and transducer absence, but does not detail implementation internals.
Examples
Demonstrates lazy construction with a side-effecting infinite sequence and contrasts the function with neighboring sequence APIs.
What it assumes
Assumes familiarity with sequential inputs, numeric arguments, and lazy sequence results.
What you can do after
Apply it via Clojure to lazily remove trailing elements from sequential data.
How it connects
Relates to sequences, lazy evaluation, drop, take, take-last, and transducers through shared selection behavior.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.