May 2018
Beginner to intermediate
290 pages
6h 43m
English
The rule for modifying maps is pretty simple: you can’t. In exactly the same way that lists and vectors are immutable, maps are stubbornly resistant to change. But like lists and vectors, you can create a new map that is a modified copy of an existing map. One way you can make a modified copy is to add a key to a value, which you can do with assoc:
| | (assoc book :page-count 362) |
Which will give you this:
| | {:page-count 362 |
| | :title "Oliver Twist" |
| | :author "Dickens" |
| | :published 1838} |
Using assoc is easy. You supply the original map, along with a key and a value, and you will get back a new map, just like the old one but with the key set to the new value. You can also feed more than one key/value pair ...
Read now
Unlock full access