Collection >> #removeIdentical:

Leandro Caniglia caniglia at dm.uba.ar
Wed Sep 20 18:30:00 UTC 2006


Hi Diego.

My claim was that #removeAllSuchThat: won't work in the general case. The
reason is that it uses #remove:. In consequence, the first element which is
= to the argument gets removed. However, #removeIdentical: was intended to
remove the argument, and not another object that equals it. Note also that
your examples work because your sets have only one #a, so there is no
ambiguity between = and ==.

Note also that I asked this question as an "exercise" and not because of any
practical needs.

/Leandro


----- Original Message ----- 
From: "Diego Fernandez" <diegof79 at gmail.com>
To: "The general-purpose Squeak developers list"
<squeak-dev at lists.squeakfoundation.org>
Sent: Wednesday, September 20, 2006 11:02 AM
Subject: Re: Collection >> #removeIdentical:


> It's really strange, these two works in my image (Squeak-3.9-7058):
>
> (Set withAll: #(a b c a) ) removeAllSuchThat: [:x | x == #a ].
> (OrderedCollection withAll: #(a b c a) )
>      removeAllSuchThat: [:x | x == #a ].
>
> May be you can get the same effect with something like this:
> (the worst case it's O(n^2) like removeAllSuchThat: in Collection)
>
> | s |
> s := Set withAll: #(a b c a).
> s removeAll: (s select: [:x | x == #a ]).
>
> It's really necesary to keep the same Collection instance (why not
> simply reject:) ?
>
> On 9/19/06, Leandro Caniglia <caniglia at dm.uba.ar> wrote:
>>
>>
>> What's the best way to implement the method of the subject?
>>
>> self removeAllSuchThat: [:x | x == anObject] won't work.
>>
>> /Leandro
>>
>>
>>
>>
>




More information about the Squeak-dev mailing list