I refactored a code from:
def do_something(attribute) do
bar = get_bar(attribute)
baz = get_baz(bar)
do_something_else(attribute, bar, baz)
end
defp do_something_else(_first, _second, 12381), do: {:ok, :ignored}
defp do_something_else(_first, second, _third) when length(second) > 100, do: {:ok, :ignored}
defp do_something_else(first, second, third), do: ExternalService.call(first, second, third)
to:
def do_something(attribute) do
bar = get_bar(attribute)
baz = get_baz(bar)
case {attribute, bar, baz} do
{_first, _second, 12381} -> {:ok, :ignored}
{_first, second, _third} when length(second) > 100 -> {:ok, :ignored}
{first, second, third} -> ExternalService.call(first, second, third)
end
end
I replaced the private functions with a case. AFAIK I can’t use multiple values on the case clause, I wrapped them in a tuple. Is this the idiomatic way to do it?