Re: [Pharo-users] OrderedCollection remove:

2015-04-03 Thread Ramon Leon
On 04/01/2015 11:22 PM, Peter Uhnák wrote: col := #(1 2 3 4 5) asOrderedCollection. col do: [ :each | col remove: each. ]. col As a general rule in Smalltalk, a lot of hassle can be avoided avoiding loops. If you think you need a loop, stop and find a better way, it likely already exists, in

Re: [Pharo-users] OrderedCollection remove:

2015-04-02 Thread Alexandre Bergel
col := #(1 2 3 4 5) asOrderedCollection. col copy do: [ :each | col remove: each. ]. col will work instead Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;. > On Apr 2, 2015, at 3:22 AM, Pete

Re: [Pharo-users] OrderedCollection remove:

2015-04-02 Thread jtuc...@objektfabrik.de
Peter, several approaches have been shown already. I'd like to add: * Iterate over a copy and remove from the original (slower because of lookup in the original) * If possible, sort the collection and use something like [col atEnd] whileTrue:/whileFalse: with removeFirst/removeLast * Select:

Re: [Pharo-users] OrderedCollection remove:

2015-04-02 Thread Sean P. DeNigris
BriceG wrote > Hi, > it depends on what is your goal but if you want to clean an > OrderedCollection there's removeAll of if you want to remove specific item > there's removeAllSuchThat:aBlock > > I had the following code working for your example: > > col := #(1 2 3 4 5) asOrderedCollection. > a

Re: [Pharo-users] OrderedCollection remove:

2015-04-02 Thread p...@highoctane.be
On Thu, Apr 2, 2015 at 9:33 AM, Peter Uhnák wrote: > On Thu, Apr 2, 2015 at 8:30 AM, Joachim Tuchel > 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 mentione

Re: [Pharo-users] OrderedCollection remove:

2015-04-02 Thread p...@highoctane.be
On Thu, Apr 2, 2015 at 8:22 AM, Peter Uhnák wrote: > 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 tes

Re: [Pharo-users] OrderedCollection remove:

2015-04-02 Thread Peter Uhnák
On Thu, Apr 2, 2015 at 8:30 AM, Joachim Tuchel 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

Re: [Pharo-users] OrderedCollection remove:

2015-04-01 Thread Joachim Tuchel
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 : > > Hi, > > I've just run into quite a nasty surprise > > col := #(1 2