But that is kindof what I thought each() did anyway.
Can someone confirm that I was wrong to expect the first bit of code to work? Cheers.
brianThu 27 Nov 2014
Readonly safe just means that it won't raise an exception if you try it with a readonly or immutable list. So if you want to mutate the list during iteration, you definitely want to duplicate it first.
SlimerDude Thu 27 Nov 2014
The docs of
List.each()
sayThis method is readonly safe.
which I took to mean that it is not affected by subsequent changes to the list. But...Clearly the
remove()
statement affects theeach()
loop, which is not what I was expecting.I can remedy the above by calling
list.dup()
:But that is kindof what I thought
each()
did anyway.Can someone confirm that I was wrong to expect the first bit of code to work? Cheers.
brian Thu 27 Nov 2014
Readonly safe just means that it won't raise an exception if you try it with a readonly or immutable list. So if you want to mutate the list during iteration, you definitely want to duplicate it first.