dissoc-in removes the value at a path of keys or indexes from nested associative data. Clojure has no standard dissoc-in, so it must be defined when nested removal is needed. section 11.3.1
Removing a nested map entry
(def m {:a {:b 2 :c {:d 4 :e 5}}}) (dissoc-in m [:a :c :d]) ;; {:a {:b 2, :c {:e 5}}} section 11.3.1
A practical implementation should account for these behaviors:
- A simple recursive version works for maps by descending through the path and applying dissoc at the final key. section 11.3.1
- A map-only version fails when the final collection is a vector; vector removal requires removing the indexed element rather than calling dissoc. section 11.3.1
- A robust version dispatches on map? and vector?, using remove-at with subvec for vector paths. section 11.3.1
Listing 11.9. → Adding keys, Replacing values, Removing keys
(assoc ([map key val]) ([map key val & kvs])) (assoc-in [map ks val]) (dissoc ([map]) ([map key]) ([map key & ks]))
Compare dissoc-in with the related shallow and nested associative-update functions. section 11.3.1
