With Maps of Mapsλ︎
Define a collection of star-wars characters using a map of maps. Each character should have an name that they are typically referred to, along with their fullname and skill
Now we can refer to the characters using keywords. Using the get function we return all the information about Luke
By wrapping the get function around our first, we can get a specific piece of information about Luke
There is also the get-in function that makes the syntax a little easier to read
Or you can get really concise by just talking to the map directly
(star-wars-characters :luke)
(:fullname (:luke star-wars-characters))
(:skill (:luke star-wars-characters))
(star-wars-characters :vader)
(:skill (:vader star-wars-characters))
(:fullname (:vader star-wars-characters))
And finally we can also use the threading macro to minimise our code further
Create a slightly data structure holding data around several developer events. Each event should have a website address, event type, number of attendees, call for papers.
Example
(def dev-event-details
{:devoxxuk {:URL "http://jaxlondon.co.uk"
:event-type "Conference"
:number-of-attendees 700
:call-for-papers "open"}
:hackthetower {:URL "http://hackthetower.co.uk"
:event-type "hackday"
:number-of-attendees 99
:call-for-papers "closed"}})
This data structure is just a map, with each key being the unique name of the developer event.
The details of each event (the value to go with the event name key) is itself a map as there are several pieces of data associated with each event name. So we have a map where each value is itself a map.
Call the data structure and see what it evaluates too, it should not be a surprise
We can ask for the value of a specific key, and just that value is returned
In our example, the value returned from the :devoxxuk key is also a map, so we can ask for a specific part of that map value by again using its key