4 ms·
My general feeling is that if the errors matter, `with` probably isn't the right construct. In those situations I prefer to use case. That's been helpful in my
by keathley 5y ago
My general feeling is that if the errors matter, `with` probably isn't the right construct. In those situations I prefer to use case. That's been helpful in my experience.
- devoutsalsa 5y agoIf 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!