I've noticed that in Clojure it's common to use keywords as keys in a map, while in other languages that do not have such concept it is common to use strings.
What are benefits of using keywords instead of strings or other types?
get
with themselves as the key argument. This is convenient for cases like "I want the phone number of all these people" - (map :phone-no people)
vs. (map #(get % "phone-no") people)
Keywords are also convenient with let
and other destructuring tools:
(let[{:keys [foo bar]} {:foo 1 :bar 30}]
(+ foo bar)) ;;=>31
but this does actually apply to string keys as well using the less common :strs
destructuring.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With