Reputation: 133
Trying to filter a sequence of maps that have a value for a key in a list of values.
Trying to do something like this
=> (filter (fn [foo]
#(some(:x foo) ["0000", "2222"]))
[{ :y "y" :x "0000"} {:y "y" :z "z" :x "1111"} {:y "y" :z "z" :x "2222"}])
; I want to return this
=> [{:y "y" :z "z" :x "1111"}]
edit: fixed typo
Upvotes: 1
Views: 531
Reputation: 16194
This produces the desired output:
(filter #(not (#{"0000", "2222"} (:x %)))
[{:y "y" :x "0000"}
{:y "y" :z "z" :x "1111"}
{:y "y" :z "z" :x "2222"}])
=> ({:y "y", :z "z", :x "1111"})
This solution is using a set of those two strings, and testing :x
of each input map for set membership.
I think you have a typo and some other issues in your filter predicate example. I fixed the "0000"
typo in this example to get the desired output.
Upvotes: 2