Skip to content

Instantly share code, notes, and snippets.

@ktravers
Created July 12, 2018 03:08
Show Gist options
  • Save ktravers/c81a006c9aff519314accdc7b546dda4 to your computer and use it in GitHub Desktop.
Save ktravers/c81a006c9aff519314accdc7b546dda4 to your computer and use it in GitHub Desktop.
# Not recommended: macros
defmodule Account.Guards do
defmacro is_private(first_name, email) do
quote do
not(is_nil(unquote(first_name))) and
not(unquote(email) == unquote(first_name))
end
end
end
# Recommended: defguard
defmodule Account.Guards do
defguard is_private(first_name, email) when not(is_nil(first_name)) and not(email == first_name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment