Skip to content

Instantly share code, notes, and snippets.

@fay-jai
Created November 15, 2018 05:50
Show Gist options
  • Save fay-jai/a343c3d0adc3ccdfbc4f5430d3adb9f8 to your computer and use it in GitHub Desktop.
Save fay-jai/a343c3d0adc3ccdfbc4f5430d3adb9f8 to your computer and use it in GitHub Desktop.
# How to invoke an anonymous function in Elixir
greet = fn (name) -> "Hello, #{name}" end
greet.("Willson") # Notice the dot right after variable name but before the opening parentheses
# How to invoke a named function in Elixir
defmodule Greeter do # This is an Elixir module, and for the purposes of this example, it's simply a container for named functions
def greet(name), do: "Hello #{name}" # Here we're defining a new named function `greet`
end
Greeter.greet(name) # And here we're invoking the named function. Notice that there isn't a dot right after the function name and before the opening parentheses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment