The map data structure in clojure is entirely similar to ones in other languages– key/value based data storage/access. In most other languages that i use, map access/setting is O(1), which is part of their advantage. In clojure access is log32n but at least we’re getting the benefits of immutable, persistent storage.
Pretty easy to make a map:
Clojure has a few types of maps. We’ll only be investigating hash maps in this article, though.
Map Data Access
Its super easy to get data out of a map.
Note that like vectors, you can use maps as the functions to access their values.
Modification
Again, maps are immutable and persistent– so functions that modify them return new objects with the old object left unchanged.
assoc is (from what I observe) the most used method to modify a map.
Interesting how assoc-in takes a map and a vector and updates “within” a structure. Seems really useful for nested scenarios.