Created
November 23, 2023 04:17
-
-
Save sionide21/cdeb122109ea3cfa317880bd28890874 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
defmodule Debug do | |
defmacro debug_case(ast) do | |
ast | |
|> Macro.postwalk(fn | |
{:->, ctx, [[clause], expr]} -> | |
debug = quote do | |
IO.puts("Hit clause: #{unquote(Macro.to_string(clause))}") | |
end | |
{:->, ctx, [[clause], {:__block__, [], [debug, expr]}]} | |
ast -> ast | |
end) | |
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 MyCode do | |
require Debug | |
def some_function(input) do | |
case {input, 0} do | |
{:cat, _} -> "Meow" | |
{:dog, 0} -> "Woof" | |
_ -> "???" | |
end | |
|> Debug.debug_case | |
end | |
end | |
iex(1)> MyCode.some_function(:cat) | |
Hit clause: {:cat, _} | |
"Meow" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment