I have struct map like this
(def admin (struct-map person :first-name "Name" :last-name "Last name"))
So, now I would like to add new key-value pair to this map, and have it look something like
(def admin (struct-map person :first-name "Name" :last-name "Last name" :username "username"))
How do I do this?
I know that it won't be the same structure after this, but it doesn't matter.
If you are not concerned with retaining the structure, assoc
will add your new key-value pair.
(defstruct person :first-name :last-name)
(def admin (struct-map person
:first-name "Name"
:last-name "Last name"))
(assoc admin :username "username")
;=> {:first-name "Name", :last-name "Last name", :username "username"}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.