May 2018
Beginner to intermediate
290 pages
6h 43m
English
Destructuring is one of those convenience features that always seems to leave you wanting more. For instance, consider that when destructuring a map with keyword keys, people tend to use symbols that look just like the keys. If, for example, we were working with maps that looked like this:
| | {:name "Romeo" :age 16 :gender :male} |
we might be inclined to bind the value of :name to name, :age to age, and :gender to gender:
| | (defn character-desc [{name :name age :age gender :gender}] |
| | (str "Name: " name " age: " age " gender: " gender)) |
This does work, but there’s a lot of repetition in the code as we repeat our way through name :name age :age gender :gender. If only we could just say, Oh, and pull out :name, :age, and
Read now
Unlock full access