Credence.Pattern.NoReduceWhileWithoutHalt
(credence v0.7.0)
Copy Markdown
Detects Enum.reduce_while/3 where every callback clause returns only
{:cont, value} — never :halt or {:halt, value}. This is equivalent
to plain Enum.reduce/3 and the reduce_while adds unnecessary ceremony.
Bad
Enum.reduce_while(list, 0, fn x, acc ->
{:cont, acc + x}
end)
list
|> Enum.reduce_while({0, []}, fn h, {max, acc} ->
new_max = max(h, max)
{:cont, {new_max, [new_max | acc]}}
end)Good
Enum.reduce(list, 0, fn x, acc ->
acc + x
end)
list
|> Enum.reduce({0, []}, fn h, {max, acc} ->
new_max = max(h, max)
{new_max, [new_max | acc]}
end)Auto-fix
Replaces reduce_while with reduce and unwraps each {:cont, value}
return to just value.