Sorry, I was unclear. The example implementation was an example of how the 
function would work, not how it would be implemented. I was imagining an 
implementation that didn't build an intermediate list. Is building a new 
map each step too expensive for this to be considered composable? There's 
already Map.take/2 which is somewhat similar in functionality to 
filter_keys. 

On Saturday, June 18, 2016 at 6:27:07 PM UTC+2, 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/db856a1a-3637-480b-bef6-caf8c808782e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to