April 2, 2015
6:30 a.m.
Peter, In general, removing from a Collection while iterating through it leads to undefined results. The same is true for adding. Just never do it Joachim
Am 02.04.2015 um 08:22 schrieb Peter Uhnák <i.uhnak@gmail.com>:
Hi,
I've just run into quite a nasty surprise ~~~~~~~~~~~~~~~~ col := #(1 2 3 4 5) asOrderedCollection. col do: [ :each | col remove: each. ]. col ~~~~~~~~~~~~~~~~ it throws "NotFound: nil not found in OrderedCollection" I tested it also in Pharo3 and there it just silently removed first, third and fifth element.
Looking at the implementation of OrderedCollection>>do: it seems that doing what I'm doing is a bad idea.
So what shall one do:? col copy do: [...] ?
Why can't do: be a bit smarter? Optimization?
Thanks, Peter