Using Clojure update-in with multiple keys

clojure, dictionary

Solution

`update-in` is to update a single key in the map (at a particular nesting level, `[:a :b]` means update key :b inside the map value of key :a.

What you want can be done using reduce:

(reduce #(assoc %1 %2 (str "X-" (%1 %2)))
        mymap
        [:a :b])

Problem

I'm trying to apply a function to all elements in a map that match a certain key. ``` (def mymap {:a "a" :b "b" :c "c"}) (update-in mymap [:a :b] #(str "X-" %)) ``` I'm expecting ``` {:a "X-a", :c "c", :b "X-b"} ``` But I get ClassCastException java.lang.String cannot be cast to clojure.lang.Associative clojure.lang.RT.assoc (RT.java:702) Anyone can help me with this?

Original source