Open alienfluid opened 7 years ago
So i just read the only other issue that it's about the same val
:). I've also been using the wrong term - map instead of tuple. Lots to learn.
In the comment on that issue, it is mentioned that {:inches, inches} = val
will pattern match such that the second value in val
will be bound to inches
as long as :inches
is the first element. Makes sense, but then why is Elixir giving me a warning?
val
is the same as the tuple on the left. It is unused, so redundant here. But it could be useful if the function needed the whole tuple, not only its part, e.g., to pass it to another function:
def discount({:order_item, amount} = item, user) do
amount * discount_rate(item, user)
end
It's safe to remove = val
, in order to make the warning disappear.
Just started working through this book and it's been great so far!
A quick question on this example though --
What is
val
(in the functional argument) used for? When I run the tests, I get this warning:What is the point of
val
in this example? Also, isval
bound to the map that is passed as argument?Thanks!