I have a problem, where i have a macro the calls another function. I want to be able to add optional guards to my macro, and call the nested function with those guards. I have a solution, but i feel like it is verbose and there is something i dont know of. Its the use of case do that feels clunky, and the only difference is the when clause.
Example
defmacro assert_push(
event,
payload,
timeout \\ 100
) do
case payload do
{:when, _, [pattern, guard]} ->
quote do
assert_receive %Phoenix.Socket.Message{
event: unquote(event),
payload: unquote(pattern)
}
when unquote(guard),
unquote(timeout)
end
_ ->
quote do
assert_receive %Phoenix.Socket.Message{
event: unquote(event),
payload: unquote(payload)
},
unquote(timeout)
end
end
end






















