Btw, there are a number of ways to write that expression depending on the complexity of the function
Short syntax:
Enum.map [1,2,3], &(&1 * &1)
Long syntax: Enum.map [1,2,3], (fn num ->
num * num
end)
Or even: square_me = &(&1 * &1)
Enum.map [1,2,3], square_me
square_me_too = fn(num) -> num * num end
Enum.map [1,2,3], square_me_too
Defining a function separately (e.g. even in another module) and referencing it: def square(num) do
num * num
end
def doing_something() do
...
Enum.map [1,2,3], &square/1
Enum.map [1,2,3], &SomeOtherModule.square/1
...
end