On Thu, Apr 2, 2015 at 9:33 AM, Peter Uhnák <i.uh...@gmail.com> wrote:

> On Thu, Apr 2, 2015 at 8:30 AM, Joachim Tuchel <jtuc...@objektfabrik.de>
> wrote:
>
>> In general, removing from a Collection while iterating through it leads
>> to undefined results. The same is true for adding.
>>
> That is a question of approach; apart from mentioned #copy I could also do
> something like
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> col := #(1 2 3 4 5) asOrderedCollection.
> [col isNotEmpty] whileTrue: [ col remove: col first ].
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> if I had an Iterator I could also reset it after each change.
>
> What I am asking is what the best approach would be - I want do some
> processing for each item and remove it from the collection after it is done.
>

"If process indicates if it is worth removing the item"
processed:= col select: [ :each |  col process: each ].
col removeAll: processed.

It is an interesting dicussion actually :-)

Phil




>
> Peter
>

Reply via email to