Skip to content

Instantly share code, notes, and snippets.

@krainboltgreene
Last active December 12, 2021 01:23
Show Gist options
  • Save krainboltgreene/24f2a63fdc29303bfca5b509e5c5c10c to your computer and use it in GitHub Desktop.
Save krainboltgreene/24f2a63fdc29303bfca5b509e5c5c10c to your computer and use it in GitHub Desktop.
defmacro example(keys) when is_list(keys) do
quote do
example(unquote(keys), defer_to: __MODULE__, loaded: false)
end
end
defmacro example(keys, defer_to: defer_to) when is_list(keys) do
quote do
example(unquote(keys), defer_to: unquote(defer_to), loaded: false)
end
end
defmacro example(keys, loaded: loaded) when is_list(keys) and is_boolean(loaded) do
quote do
example(unquote(keys), defer_to: __MODULE__, loaded: unquote(loaded))
end
end
defmacro example(keys, defer_to: defer_to, loaded: loaded) when is_list(keys) and is_boolean(loaded) do
quote do
real code here
end
end
defmodule Example do
import MacroExample
defrandomized([:a, :b, :c])
defrandomized([:a, :b, :c], defer_to: A)
defrandomized([:a, :b, :c], loaded: true)
defrandomized([:a, :b, :c], defer_to: A, loaded: true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment