Last active
June 18, 2017 19:48
-
-
Save imranismail/464fc1622b722e5ab11674db091ac083 to your computer and use it in GitHub Desktop.
Trying to figure out function head bindings for Elixir Macro
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 Aggregate do | |
defmacro replay(struct, aggregate, do: block) do | |
quote bind_quoted: [struct: struct] do | |
@events [struct|@events] | |
def __replay__(struct, unquote(aggregate)), do: unquote(block) | |
end | |
end | |
end | |
defmodule User do | |
defstruct [:activated?] | |
replay %UserCreated{} = event, aggregate do | |
%{aggregate | activated?: event.activated?} | |
end | |
end | |
def User do | |
def __replay__(%UserCreated{} = event, aggregate) do | |
%{aggregate | activated?: event.activated?} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment