ClojureDocs

Nav

Namespaces

dissoc!

clojure.core

Available since 1.1 (source)
  • (dissoc! map key)
  • (dissoc! map key & ks)
Returns a transient map that doesn't contain a mapping for key(s).
1 Example
;; dissoc! works on a transient map

;; WARNING: Below is an example of what is called "bashing in place" of
;; a transient, and is _NOT_ the correct way to use transients.  See assoc!
;; examples for some discussion of the reason.
;; Also see one example for conj! that contains a detailed example
;; of a wrong result that can occur if you do not use its return value.

(let [my-map (transient {:x 1 :y 2 :z 3})]
  (dissoc! my-map :x)   ; mistake is to use my-map below, not dissoc! return val
  (persistent! my-map)) ; returns persistent map {:y 2 :z 3}


;; Here is a correct way to do the operation described above:

(let [my-map (transient {:x 1 :y 2 :z 3})
      x (dissoc! my-map :x)]    ; after this, don't use my-map again, only x
  (persistent! x))    ; returns persistent map {:y 2 :z 3}
See Also

When applied to a transient map, adds mapping of key(s) to val(s). When applied to a transient vec...

Added by jafingerhut

Adds x to the transient collection, and return coll. The 'addition' may happen at different 'place...

Added by jafingerhut
0 Notes
No notes for dissoc!