Daniel Compton

The personal blog of Daniel Compton - Projects

Getting Clojure map entries

Sometimes when you’re working with Clojure maps you want to get both the key and the value together. To do this, use find. find returns a clojure.lang.MapEntry which looks and smells like a two element vector, and can be manipulated like one.

(find {:key :val} :key)
;; => [:key :val]

(type (find {:key :val} :key))
;; => clojure.lang.MapEntry