30 ms·
If the errors don't matter & there's no real chance of returning an error, why use &with/1 at all? &with/1 has the quirky behavior in that the return value of a
by devoutsalsa 5y ago
If the errors don't matter & there's no real chance of returning an error, why use &with/1 at all? &with/1 has the quirky behavior in that the return value of anything that doesn't pattern match get returned. So if &call_service/1 or &parse_response/1 doesn't return an an ok tuple, you're increasing your debugging surface by having to track down where the unexpected result came from. Good luck tracking down that rogue nil!
Instead of this...
with {:ok, response} <- call_service(data),
{:ok, decoded} <- parse_response(response) do
decoded
end
Maybe just do this...
{:ok, response} = call_service(data)
{:ok, decoded} = parse_response(response)
decoded
Or even this...
data
|> call_service!() # don't bother returning ok tuples
|> parse_response!() # just use bang methods!