1.2.0 permalink Arrow_down_16x16
  • (dissoc-in m [k & ks :as keys])
Dissociates an entry from a nested associative structure returning a new
nested structure. keys is a sequence of keys. Any empty maps that result
will not be present in the new structure.

1 Example top

  • user> (def x [{:a 2 :b 9} {:a 9 :b 5}])
    #'user/x
    user> (dissoc-in x [1 :a])
    [{:a 2, :b 9} {:b 5}]
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/core.clj:57 top

(defn dissoc-in
  "Dissociates an entry from a nested associative structure returning a new
  nested structure. keys is a sequence of keys. Any empty maps that result
  will not be present in the new structure."
  [m [k & ks :as keys]]
  (if ks
    (if-let [nextmap (get m k)]
      (let [newmap (dissoc-in nextmap ks)]
        (if (seq newmap)
          (assoc m k newmap)
          (dissoc m k)))
      m)
    (dissoc m k)))
Vars in clojure.contrib.core/dissoc-in: assoc defn dissoc if-let let seq
Used in 0 other vars

Comments top

1 comment(s) for dissoc-in.

"(dissoc-in x [1 :a])" can be written as "(update-in x [1] dissoc :a)"

Log in to add a comment.