liveBook · Manning

Remove

As explained in Clojure: The Essential Reference

remove is a Clojure function that returns a lazy sequence excluding the elements of a collection for which a predicate returns a truthy value.

remove is a Clojure sequence function for excluding items whose predicate returns a truthy value. It returns a potentially empty lazy sequence, preserving items for which the predicate is false. The predicate is required, must accept one argument, and should preferably be free of side effects because laziness does not guarantee once-only invocation. section 3.5.3

Use remove with either of these arities:

  • (remove pred) returns a transducer-producing function for use in a transducer pipeline. section 7.2
  • (remove pred coll) processes any sequential collection and returns a lazy sequence no larger than the input. section 3.5.3
  • Place removal early in processing pipelines when eliminating unwanted elements can avoid more expensive transformations. section 3.5.3

Removing matching values

(remove even? [1 2 3 4 5]) ;; (1 3 5) The predicate identifies elements to omit, so remove even? keeps the odd values. filter expresses the complementary operation by keeping predicate matches. section 3.5.3

Listing 3.27. → Sequence Processing, Items Selection
(filter
  ([pred])
  ([pred coll]))

(remove
  ([pred])
  ([pred coll]))

Browse the compact signatures for remove and its related filter function, including their one- and two-argument forms. section 3.5.3

How Clojure: The Essential Reference covers it

How deep it goes
Explains predicate contracts, arities, lazy results, side-effect concerns, complementary filtering, and transducer behavior.
Examples
Demonstrates removing even numbers from a vector and contrasts the result with filter's complementary behavior.
What it assumes
Assumes familiarity with one-argument functions, predicates, sequential collections, lazy sequences, and basic transformation pipelines.
What you can do after
Apply remove to lazy sequence pipelines or use its predicate-only arity as a transducer.
How it connects
Connects remove with filter, predicates, lazy sequences, sequence-processing pipelines, and transducers.

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.