dissoc-in?

60 views
Skip to first unread message

kwatford

unread,
Dec 19, 2008, 6:31:26 PM12/19/08
to Clojure
I've been using assoc-in, get-in, etc, to work with nested maps, but I
recently needed a dissoc-in to free up unneeded indexes and such. I
didn't see one, so does this look about right?

(defn dissoc-in [m keys]
(if (<= (count keys) 1)
(dissoc m (first keys))
(let [k (last keys)
restkeys (butlast keys)
submap (dissoc (get-in m restkeys) k)]
(if (empty? submap)
(recur m restkeys)
(assoc-in m restkeys submap)))))
Reply all
Reply to author
Forward
0 new messages