Skip to content

Instantly share code, notes, and snippets.

@cored
Created April 7, 2023 18:00
Show Gist options
  • Save cored/f59855cfd1b0f1b2f2d770302e27b85a to your computer and use it in GitHub Desktop.
Save cored/f59855cfd1b0f1b2f2d770302e27b85a to your computer and use it in GitHub Desktop.
defmodule Examples do
# basic defintion
def do_stuff( params ) do
"result"
end
#shorthand syntax
def shorthand(), do: "result"
# defp is for private functions
defp private_method, do: "private"
# params can pattern match
def match_this(%{:key => value}), do: value
# the first matching function is called (order matters)
def test(test), do: "matches any param"
def test([]), do: "never matched"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment