Mutare.Mutators.ClauseDrop (mutare v0.1.0)

Copy Markdown View Source

Removes one clause of a multi-clause function, so inputs it handled fall through to a later clause (or raise FunctionClauseError):

def f(0), do: :zero            def f(n), do: n + 1
def f(n), do: n + 1

Each body-bearing clause of a def/defp group is offered in turn. It asks directly whether any test pins the clause's own behaviour, rather than the behaviour of whatever it shadows.

Two conditions narrow it:

  • At least two body-bearing clauses must remain in play — a single-clause function has nothing to fall through to.
  • A bodiless head (def f(a, b) with no do, declaring default arguments or carrying docs) is never dropped. It is not a clause, so dropping it is a no-op, and dropping the implementation while the header remains leaves a defp with no body — "implementation not provided", a compile error that would poison the build.

rescue clause removal is a separate concern and belongs to the rescue_type family.

This family is enabled by default and uses the clause_drop ignore name.

Summary

Functions

name()