Skip to main content

W0044 - Simplify negation

Warning

fn (A, AIsFalseBranch, AIsTrueBranch) ->
case not A of
%% ^ 💡 weak: Consider rewriting to match directly on the negated expression.
true -> AIsFalseBranch;
false -> AIsTrueBranch
end
fn(A, AIsTrueBranch, AIsFalseBranch) ->
if not A -> AIsFalseBranch;
%% ^ 💡 weak: Consider rewriting to an equality match.
true -> AIsTrueBranch
end.

Explanation

The warning message indicates an unidiomatic way to express branching based on a negated expression.

To fix this warning, replace the use of the not operator and subsequent check of the result with a direct use of an equality pattern:

fn(A, AIsTrueBranch, AIsFalseBranch) ->
case A of
true -> AIsTrueBranch;
false -> AIsFalseBranch
end.