Going Further

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

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.