Skip to content

Instantly share code, notes, and snippets.

@tonini
Created June 19, 2013 20:07
Show Gist options
  • Save tonini/5817579 to your computer and use it in GitHub Desktop.
Save tonini/5817579 to your computer and use it in GitHub Desktop.
From the Elixir language *master* documentation.
Function retrieval
The function macro can also be used to retrieve local, imported and remote functions.
square = fn(x) -> x * x end
Enum.map [1,2,3], function(square/1)
** (UndefinedFunctionError) undefined function: :erl_eval.square/1
:erl_eval.square/1
:erl_eval.expr/3
defmodule MyMath do
def square(x) do
x * x
end
end
Enum.map [1,2,3], function(MyMath.square/1)
# [1, 4, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment