Skip to content

clojure.core/assoc-in

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 9 Runnable: 7
([m [k & ks] v])

Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created.

Examples

by zk on
by devth on
by pmbauer on
by saiberz on
by cthulhu-bot on
by prudentbot on
by amirrajan on
by gosukiwi on . May have evaluation errors.
by bfontaine on . May have evaluation errors.

Note by Crowbrammer

Unlike assoc, you can only do one kv at a time:

;; Allowed
(assoc {} :a "a" :b "b" :c "c")
;; Not allowed:
(assoc-in {} [:a :b] "cya" [:a :d :e] "f" [:b :g] "wow")

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.