liveBook · Manning

Drop

As explained in Clojure: The Essential Reference

drop is a Clojure function that removes a specified number of elements from the beginning of a sequence or returns a transducer that performs that removal.

drop removes the first n elements from a sequential input and returns the remaining sequence. With only n, it returns a transducer that skips the first n inputs during reduction. section 10.2 section 7.2

Its contract is compact but includes useful edge cases:

  • Provide n and coll for a sequence result, or provide only n for a transducer. section 10.2
  • Treat negative n as zero; accept zero, fractional, and other numeric values as permitted by the contract. section 10.2
  • Return an empty sequence when n exceeds the collection length, and reject a non-sequential coll with IllegalArgumentException. section 10.2
  • Compose the transducer with other transformations; it prevents the reducing function from receiving the first n elements. section 7.2

Skipping a prefix

(drop 3 (range 10)) ;; (3 4 5 6 7 8 9) (transduce (comp (drop 3) (map inc)) + (range 10)) ;; 49 The first form returns the tail after three elements; the second skips three inputs before applying map and reducing. section 10.2

Lazy traversal

When applied to a lazy input, drop does not necessarily realize the result immediately: (def time-bomb (drop 1e7 (xs))) creates the value without the visible traversal performed by eager operations.

How Clojure: The Essential Reference covers it

How deep it goes
Defines arities, contracts, edge cases, exceptions, laziness, and transducer behavior without descending into implementation internals.
Examples
Uses ranges, lazy generated sequences, HTTP records, and a composed transducer to demonstrate prefix removal.
What it assumes
Assumes familiarity with sequential inputs and reductions while specifying the required n, coll, and transducer forms.
What you can do after
Apply it via Clojure sequence operations or transducer composition to discard a known number of leading inputs.
How it connects
Connects sequential selection with sequences, transducers, take, drop-while, map, and reducing functions.

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.