Clojure get map key by value

前端 未结 3 1774
失恋的感觉
失恋的感觉 2020-12-31 11:58

I\'m a new clojure programmer.

Given...

{:foo \"bar\"}

Is there a way to retrieve the name of the key with a value \"bar\"?

3条回答
  •  暖寄归人
    2020-12-31 12:41

    As in many other cases you can use for:

    (def hm {:foo "bar"})
    (for [[k v] hm :when (= v "bar")] k)
    

提交回复
热议问题