“`{iex}
f = fn a -> case a do
%{_a, _b, _c} -> “A tuple of size 3, so what?”
_ -> “Uhh…. what’s that?”
end
end
“`
I get the following error: `** (CompileError) iex:24: expected key-value pairs in a map, got: _a`
Am I running a too old Elixir-Erland/OTP combo? Elixir v1.12..2 on Erlang 24 erts 12.2.1
I think the issue is you put a “%” on the front, making the datastructure a Map, but it’s and invalid structure for a map. Remove the “%” for it to be a tuple.
Case statements are used a lot in Elixir. They are one of the easiest ways to go a pattern match whenever you need it. Multiple function heads that use pattern matching actually turn into case statements when compiled. There are mixed feelings in the community about piping directly into a |> case do. I think that’s what you may have been seeing.
Excellent !!!
Awesome. I’m understanding more pattern matching.
Outstanding! 🎹 🎷 🎻 🎯
This is really helpful thanks.
When executing the following in `iex`:
“`{iex}
f = fn a -> case a do
%{_a, _b, _c} -> “A tuple of size 3, so what?”
_ -> “Uhh…. what’s that?”
end
end
“`
I get the following error: `** (CompileError) iex:24: expected key-value pairs in a map, got: _a`
Am I running a too old Elixir-Erland/OTP combo? Elixir v1.12..2 on Erlang 24 erts 12.2.1
I think the issue is you put a “%” on the front, making the datastructure a Map, but it’s and invalid structure for a map. Remove the “%” for it to be a tuple.
*insert-huge-facepalm-image-here*
You were right on target. Working like a charm now.
Thanks for the course and for your time.
Erm, I read that case do is not proper functional programming, and that we should use functional clauses.
Case statements are used a lot in Elixir. They are one of the easiest ways to go a pattern match whenever you need it. Multiple function heads that use pattern matching actually turn into case statements when compiled. There are mixed feelings in the community about piping directly into a
|> case do
. I think that’s what you may have been seeing.