Digging into Maps

There’s even more good news with destructuring: it also works with maps. The idea behind destructuring a map is the same as with the sequential types. You provide a template for the data structure—a template that includes the symbols that you want to bind to various values in the map. To see how map destructuring works, consider that when you build a map, you supply a bunch of keys and values:

 (​def​ artist-map {:painter :monet :novelist :austen})

Here we’re saying Associate :monet with :painter and :austen with :novelist. That is, this key with that value. In the template that you provide in a map destructuring, you do something very similar. You provide a series of symbols and keys. Like this:

 (​let​ [{painter :painter ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.