Skip to content

Instantly share code, notes, and snippets.

@practicalli-johnny
Created November 8, 2016 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save practicalli-johnny/3a7be833cb581c36adb463e1498e54a0 to your computer and use it in GitHub Desktop.
Save practicalli-johnny/3a7be833cb581c36adb463e1498e54a0 to your computer and use it in GitHub Desktop.
;; A simple starwars collection of characters
(def starwars-characters
{:jedi ["Luke Skywalker"
"Rey"]
:droids ["R2D2"
"BB-8"]})
;; Get all the jedi characters
(get starwars-characters :jedi)
;; Get all the droid characters
(get starwars-characters :droids)
;; A nested collection - some values are also maps
(def starwars-collection
{:characters {:jedi ["Luke Skywalker"
"Rey"]
:droids ["R2D2"
"BB-8"]}
:ships {:rebels ["Millenium Falcon"]}})
;; Get all the characters who are jedi
(get-in starwars-collection [:characters :jedi])
;; Get all the ships used by the rebels
(get-in starwars-collection [:ships :rebels])
;; You could also use the get function twice for the last two exercises,
;; although its more common to use the get-in function
(get (get starwars-collection :characters) :jedi)
(get (get starwars-collection :ships) :rebels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment