When you use function name without "&" symbol, Elixir will try to run it. Passing convert/1 without "&" symbol will casue the following error: function convert/0 is undefined or private.
The "&" symbol is named the capture operator. It allows for named functions to be assigned to variables or passed as the arguments. When using it you have to define specific arity of the function.
As far as I understand how Elixir works, using Map makes the code DRYer, but it doesn't leverage Elixir and BEAM optimization process.
With @p1_wins_table[p1] Map is accessed during runtime, where def ("scissors"), do:... are optimized during compilation and there's no need to lookup for proper values in the Map on runtime. For the sake of this kata, this may seem irrelevant but may play a significant role in real-world use cases.
When you use function name without "&" symbol, Elixir will try to run it. Passing
convert/1
without "&" symbol will casue the following error:function convert/0 is undefined or private
.The "&" symbol is named the capture operator. It allows for named functions to be assigned to variables or passed as the arguments. When using it you have to define specific arity of the function.
You can read more about it on https://elixir-lang.org/getting-started/modules-and-functions.html#function-capturing
I feel soooo stupid 😂
As far as I understand how Elixir works, using Map makes the code DRYer, but it doesn't leverage Elixir and BEAM optimization process.
With
@p1_wins_table[p1]
Map is accessed during runtime, wheredef ("scissors"), do:...
are optimized during compilation and there's no need to lookup for proper values in the Map on runtime. For the sake of this kata, this may seem irrelevant but may play a significant role in real-world use cases.More info: https://medium.com/@amuino/maps-vs-pattern-matching-in-elixir-e69b7bb11b5d