There may be several key / value pairs with a value of "bar". Values ββare not hashed for search, opposite to their keys. Depending on what you want to achieve, you can find the key using a linear algorithm, for example:
(def hm {:foo "bar"}) (keep #(when (= (val %) "bar") (key %)) hm)
or
(filter (comp #{"bar"} hm) (keys hm))
or
(reduce-kv (fn [acc kv] (if (= v "bar") (conj acc k) acc))
which will return the keys section. If you know that your vals are different from each other, you can also create a hash map with reverse lookup using
(clojure.set/map-invert hm)
Leon Grapenthin
source share