Your example implementation shows why this isn't really necessary. Moreover 
it doesn't compose well. Consider:

map
|> Enum.filter(fn {k, v} -> key_filter(k) && value_filter(v) end)
|> Map.new

vs

map
|> Map.filter_keys(key_filter)
|> Map.filter_values(value_filter)

In the latter it starts as a map, becomes a list, becomes a map again, then 
becomes a list, then becomes a map again.

There are a common set of operations which make sense for both lists, maps, 
streams, and other user made datastructures. Those common operations have 
been extracted into the Enum module based on the Enumerable protocol, and 
thats where they belong.

On Saturday, June 18, 2016 at 12:27:07 PM UTC-4, Filip Haglund wrote:
>
> I wish there was a Map.filter_values function that would filter on keys or 
> values, but leave the other one intact. This seems like something that 
> should be in the standard library.
>
> Example implementation of a Map.filter_values that would filter a map 
> based on its values, leaving the keys intact:
>
> @doc """
> Filter map based on its values, leaving the corresponding keys intact.
> """
> @spec map_filter_values(Map.t, (any -> boolean)) :: Map.t
> def map_filter_values(map, func) do
>   map |> Enum.filter(fn {_, val} -> func.(val) end) |> Map.new
> end
>
>
>
> A corresponding Map.filter_keys would also be nice.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/733241e6-7490-4093-af3f-3825eba79c7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to