assoc-in returns an associative collection with a value added or replaced at a nested key path. It generalizes assoc across maps and other associative structures, including vectors. section 11.3.1
Use the three-argument form:
- (assoc-in map ks val) follows each key in ks, then associates val at the final location. section 11.3.1
- The input collection may be nil, which defaults to an empty map; nested vector paths should contain integers. section 11.3.1
- A missing or invalid path can raise exceptions, including IndexOutOfBoundsException, IllegalArgumentException, or ClassCastException. section 11.3.1
Replace a nested vector element
(def m {:a "1" :b "2" :c {:x1 {:x2 "z1"}}}) (assoc-in m [:c :x1 :x2] "z2") ;; {:a "1" :b "2" :c {:x1 {:x2 "z2"}}}
