Given this function, what does &1 refer to?
Enum.map [1, 2, 3, 4], &(&1 * 2)
&1 refers to the first argument the callback function would receive. The ampersand by itself (&) is a shorthand for a captured function. This is how you could expand that function.
Enum.map([1, 2, 3, 4], fn x -> x * 2 end)
fn -> is equal to &(...
x -> x is equal to ...(&1
A quick reference can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With