liveBook · Manning

Drop_while

As explained in Clojure: The Essential Reference

drop-while is a Clojure function that removes the longest prefix of a sequence whose elements satisfy a predicate or returns a transducer that performs that removal.

drop_while removes the longest contiguous prefix of a sequence whose elements satisfy a one-argument predicate. It stops at the first element for which the predicate returns false, then keeps that element and the remaining tail. section 10.2

Use either sequence-producing or transducer form:

  • (drop-while pred coll) returns a lazy sequence; coll may be any sequential input or nil. section 10.2
  • (drop-while pred) returns a transducer that delays reduction until the predicate first returns false. section 10.2 section 7.2
  • The function consumes only the leading matching run; later elements do not affect where dropping stops. section 10.2

Skipping nonmatching data before tokenizing

A tokenizer can skip nonmatching digits, take the next matching run, and recur on the remaining sequence: (tokenize odd? '(1 4 1 5 9 2 6 4 3 5 8 9 3 2 6)) produces ((1) (1 5 9) (3 5) (9 3)).

Composing the transducer form

(transduce (comp (drop 3) (map inc)) + (range 10)) produces 49. The drop_while transducer can occupy the same compositional role when a predicate should control when reduction begins. section 7.2

How Clojure: The Essential Reference covers it

How deep it goes
Defines predicate stopping behavior, lazy output, transducer arity, and invalid sequential-input handling.
Examples
Demonstrates lazy digit tokenization and transducer composition over a numeric range.
What it assumes
Assumes one-argument predicates and sequential inputs while defining both sequence and transducer forms.
What you can do after
Apply it to lazily skip a predicate-matching prefix or compose that behavior into a transducer pipeline.
How it connects
Connects predicate-based selection with take-while, drop, filter, remove, and transducers.

Also explained in

Compare how 2 books explain drop_while →

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.