Funnily enough. The same topic popped in recently when we were upgrading a quite old credo version.
We decided to get rid of the rule.
For me, it depends.
We have a bunch of modules where all the functions are pipelines and only one of them had a single case:
defmodule A do
def a do
with {:ok, a} <- do_a(),
{:ok, b} <- do_b() do
{:ok, b}
end
end
def b do
with {:ok, c} <- do_c(),
{:ok, d} <- do_d() do
{:ok, d}
end
end
def c do
with {:ok, e} <- do_e() do
{:ok, e}
end
end
end
The rule that a single-case with
statement should always be rewritten to case
did not make much sense in that scenario. Other than consistency, I always pitch for using the simplest tool for the job. Case is simpler than with.