Yup, makes sense! So
%{x: a} = %{} = %{x: 1, y: 2}
is like:
%{} = %{x: 1, y: 2}
followed by:
%{x: a} = %{x: 1, y: 2}
Yup, makes sense! So
%{x: a} = %{} = %{x: 1, y: 2}
is like:
%{} = %{x: 1, y: 2}
followed by:
%{x: a} = %{x: 1, y: 2}
Something I didn’t see mentioned, which is worth knowing, is that when you match on a struct, you are really just telling the beam to match a map with a particular value in an entry with the key __struct__
.
e.g.
def update_user(%User{} = user, updates) do
Is equivalent to
def update_user(%{__struct__: MyApp.User} = user, updates) do
Great clarification. I was wondering why this works, since on one hand there always are default values when a struct is defined, on the other hand they seem to be ignored in this pattern except for the struct field.