I recently wrote some code
defp apply_result_parse(cmd,result_map, attribute_map) do
{ tag, parse_f } = Map.get(attribute_map, cmd)
result = Map.get(result_map, cmd)
value = parse_f.(result)
%{tag => value}
end
And my first thought was, “How can I write this as a pipe?”
And while it’s obvious that you can get rid of the tmp variables result
and value with this code.
defp apply_result_parse(cmd,result_map, attribute_map) do
{ tag, parse_f } = Map.get(attribute_map, cmd)
%{tag => result_map
|> Map.get(cmd)
|> parse_f.() }
end
But I find the first version a whole lot more readable. As I do more and more elixir,
I become more and more suspicious of pipes. They do make some things much more
straight forward, but I think they can just as easily obsfucate code.
Am I just falling into my default retro-grouch thinking?