Skip to content

Instantly share code, notes, and snippets.

@ktravers
Created July 12, 2018 03:06
Show Gist options
  • Save ktravers/a9dbeae69c7db8acb3778b5fbd06a4de to your computer and use it in GitHub Desktop.
Save ktravers/a9dbeae69c7db8acb3778b5fbd06a4de to your computer and use it in GitHub Desktop.
Guard clauses
defmodule Account do
def display_name(%{first: first, last: last}) when not is_nil(first) do
String.trim("#{first} #{last}")
end
def display_name(%{username: username}) when not is_nil(username) do
"#{username}"
end
def display_name(_), do: "New User"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment