Reputation: 8988
With the following list of maps:
[%{test: %{"one" => 1, "three" => 3, "two" => 2}}, ...]
Shouldnt this code not filter anything at all?
Enum.filter([map], fn(number) ->
Enum.each(number.test, fn {k, v} ->
v == 4
end)
end)
How can I make Enum.filter work with a property which is a map itself?
Upvotes: 1
Views: 228
Reputation: 222148
Enum.each
returns :ok
so your code will always return the same value as input.
If you want to check that any value in the map has value 4, you can use Enum.any?/2
:
Enum.any?(number.test, fn {k, v} ->
v == 4
end)
To check if all of them have value 4, you can use Enum.all?/2
:
Enum.all?(number.test, fn {k, v} ->
v == 4
end)
Upvotes: 2