Created
July 21, 2020 13:52
This file contains hidden or 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 Common do | |
defmacro __using__(_opts) do | |
quote do | |
def validate(thing) do | |
Common.validate({__MODULE__, thing}) | |
end | |
end | |
end | |
def validate({impl, thing}) do | |
IO.puts "Validate #{inspect(thing)} with #{impl}" | |
end | |
end | |
defmodule Customer do | |
use Common | |
end | |
defmodule Product do | |
use Common | |
end | |
Customer.validate([1,2,3]) | |
Product.validate(%{:a => "A"}) | |
# run with elixir sub.exs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment