I try to delete the last element from a list within a
defp in phoenix channel:
passed_params value is
["-0.75", "0.75", "0m", "16.67m", "0m", "0", "16.67m", "0"]
, I tried:
passed_params = List.delete_at(passed_params, length(passed_params)-1)
I get error at that line:
[error] GenServer #PID<0.495.0> terminating
** (ArithmeticError) bad argument in arithmetic expression```
However, if I try the same code in `iex` it works and remove the last element without error
You can just do:
LostKobrakai already told you how to achieve your goal.
As to why you’re getting the error, it’s likely due to a parsing issue (can’t confirm at the moment):
-1 is just a number (negative one). So this would probably work with your original code:
List.delete_at(passed_params, length(passed_params) - 1) (note the spaces around the
That’s strange, I tried different ways, including
List.delete_at(passed_params, -1) they all work without error in the
iex but not in phoenix channel…
I’ve doubled checked it, no space…
Why would it fail inside channel?!
Does your test for that channel pass? Have you setup socket channel tests?
Can you please share full code?
Perhaps the problem is somewhere else?
I did not setup socket channel tests, I will try to assemble minimum code that reproduce the issue, thanks