Idiomatic way of checking if a key on a map has a value

Viewed 4830

What is the idiomatic way of checking if a key on a map has a value? For example if we have:

=> (def seq-of-maps [{:foo 1 :bar "hi"} {:foo 0 :bar "baz"}])

To find out all the maps with :foo == 0, I like:

=> (filter (comp zero? :foo) seq-of-maps)
({:foo 0, :bar "baz"})

But if I want to find all the maps with :bar == "hi", the best that I can think of is:

=> (filter #(= (:bar %) "hi") seq-of-maps)
({:foo 1, :bar "hi"})

which I don't find very readable. Is there a better/more idiomatic way of doing it?

7 Answers
Related