liveBook · Manning

Dissoc

As explained in Clojure: The Essential Reference

dissoc is a Clojure function that returns an associative collection with specified key-value associations removed.

dissoc removes one or more specified keys from an associative collection and returns the resulting collection. It is commonly used with maps alongside assoc and assoc-in. section 11.3.1

Its contract is small but flexible:

  • The collection argument is mandatory, associative, and defaults to an empty map when nil. section 11.3.1
  • The key and any additional keys are optional; each key is matched using equality comparison. section 11.3.1
  • Vectors are associative data structures too, but dissoc keys must be integers when operating on them. section 11.3.1

Remove several map entries

(def m {:a "1" :b "2" :c "3"}) (dissoc m :a :c) ;; {:b 2}

Use dissoc in a pipeline

(-> {nil 0 :c 2} (assoc :a 1) (dissoc nil) (update :c inc) (merge {:b 2})) ;; {:c 3, :a 1, :b 2}

How Clojure: The Essential Reference covers it

How deep it goes
Defines inputs, equality matching, arities, and vector exceptions, then demonstrates multiple-key removal without covering implementation internals.
Examples
Uses map removal, threaded transformations, nil-key removal, and custom dissoc-in functions for nested structures.
What it assumes
Assumes familiarity with associative collections and equality-based key lookup while establishing the function’s argument contract.
What you can do after
Apply dissoc to remove selected keys from maps and compose the result with other associative transformations.
How it connects
Connects dissoc with maps, associative data structures, assoc, assoc-in, update, merge, and nested dissoc-in patterns.

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.