I am attempting to filter out some values from a map in Elixir.
This:
params = %{"blah" => "blah", "vtha" => "blah"}
params
|> Enum.filter fn {k, v} -> k == v end
|> Enum.map(fn {k, v} -> {k, v} end)
Result in this Error: ** (FunctionClauseError) no function clause matching in Enumerable.Function.reduce/3
But both the filter and map operations work in isolation.
Enum.filter params, fn {k, v} -> k == v end
Enum.map(params, fn {k, v} -> {k, v} end)
They don't work when piped.
I am sure I am missing something obvious.
EDIT On the master branch of Elixir, the compiler will warn if a function is piped into without parentheses if there are arguments.
You need explicit parenthesis for Enum.filter
as the function call has a stronger precedence than the pipe operator.
params = %{"blah" => "blah", "vtha" => "blah"}
params
|> Enum.filter(fn {k, v} -> k == v end)
|> Enum.map(fn {k, v} -> {k, v} end)
Please see Why Can't I Chain String.replace? for a more detailed explanation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With