A =
inside a pattern which is what you are have in your function head just measn that both sides must match. So writing %User{} = user
in a pattern means that both the struct %User
and the variable user
must match. This means that writing user = %User{}
in a pattern has the same meaning, both sides must match.
However, and this is a big however, using =
in the body of a function has a different meaning. It is a match operator, pattern = expression
which first evaluates the expression in RHS and then matches that with the pattern in the LHS. It goes right-to-left.
It was perhaps not so smart to use =
in these different ways, but it was inherited fro Erlang
I hope this hasn’t confused things.