Created
November 8, 2016 19:21
-
-
Save practicalli-johnny/3a7be833cb581c36adb463e1498e54a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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