Last active
December 12, 2021 01:23
-
-
Save krainboltgreene/24f2a63fdc29303bfca5b509e5c5c10c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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