If you want to remove matching clauses, you would generally remove them from a list of clauses:
iex(1)> quote do
...(1)> case val do
...(1)> {:ok, v} -> v
...(1)> {:error, e} -> raise e
...(1)> end
...(1)> end
{:case, [],
[
{:val, [], Elixir},
[
do: [
{:->, [],
[
[
ok: {:v,
[
if_undefined: :apply,
context: Elixir,
imports: [{0, IEx.Helpers}, {1, IEx.Helpers}]
], Elixir}
],
{:v,
[
if_undefined: :apply,
context: Elixir,
imports: [{0, IEx.Helpers}, {1, IEx.Helpers}]
], Elixir}
]},
{:->, [],
[
[error: {:e, [], Elixir}],
{:raise, [context: Elixir, imports: [{1, Kernel}, {2, Kernel}]],
[{:e, [], Elixir}]}
]}
]
]
]}
iex(2)> pruned = {:case, [],
[
...(2)> {:val, [], Elixir},
...(2)> [
do: [
...(2)> {:->, [],
...(2)> [
...(2)> [
...(2)> ok: {:v,
...(2)> [
...(2)> if_undefined: :apply,
...(2)> context: Elixir,
...(2)> imports: [{0, IEx.Helpers}, {1, IEx.Helpers}]
...(2)> ], Elixir}
...(2)> ],
...(2)> {:v,
...(2)> [
...(2)> if_undefined: :apply,
...(2)> context: Elixir,
...(2)> imports: [{0, IEx.Helpers}, {1, IEx.Helpers}]
...(2)> ], Elixir}
...(2)> ]}
...(2)> ]
...(2)> ]
...(2)> ]}
iex(3)> Macro.to_string(pruned) |> IO.puts()
case val do
{:ok, v} -> v
end
:ok
But if for instance you have a case
with a single clause, you cannot remove it, you must remove the case
expression entirely. And if the value of that expression is used, then you must remove that too, etc.
A quick and dirty hack would be to replace your clause by a value that could never match, like a ref. You inject never_match = make_ref()
and then you replace the match clauses by ^never_match
.
But it is a dirty hack. What are you trying to accomplish?