Filter or find in an array of maps by another map's values?

Is there an elegant (even terse) way of filtering or findings a map in a list of maps by the values of another map? I don’t want to hard code any keys/values, so preferably it would all be dynamic.

list_of_maps = [
  %{id: 1, one: "two", three: "four"},
  %{id: 2, one: "five", three: "six"},
  %{id: 3, one: "seven", three: "eight"},
]

# find maps with these keys/values
find_by = %{id: 2, three: "six"}

# is there a nice/terse way to do this?
my_find_method(find_by, list_of_maps)
=> %{id: 2, one: "five", three: "six"}

# a filter may return a list
my_filter_method(find_by, list_of_maps)
=> [%{id: 2, one: "five", three: "six"}]
keys = Map.keys(find_by)
Enum.find(list_of_maps, fn item -> 
  item |> Map.take(keys) |> Map.equal?(find_by)
end)
2 Likes