Most Elixir devs will agree with me, that when pattern matching on Maps,
the variable names are usually the same as the keys:
def some_method(%{user: %{id: id, email: email}, action: action, message:
message}) do
# do something
end
I propose another way to pattern match Key-Value pairs in Maps, using the
variable names alone (Similar to how you destructure objects in ES6
<https://gist.github.com/mikaelbr/9900818#file-destructuring-js-L66>):
%{ a, b } = %{a: 1, b: 2}
and
def some_method(%{user: %{ id, email }, action, message}) do
# do something
end
If this makes sense to others, I'm can try doing this and send a PR (if someone
can point me in the right direction 😊).
--
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/1d79fb43-8385-46d2-b4c9-8acca1c2407f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.