[BUG]Collection>>removeAll:

Norton, Chris chrisn at Kronos.com
Mon Aug 19 17:01:14 UTC 2002


Richard O'Keefe's code is close, but it does not always return the
collection of items that was passed in.  How about this:


removeAll: aCollection 
	"Remove each element of aCollection from the receiver. If successful
for 
	each element, answer aCollection. Otherwise create an error
notification.
	ArrayedCollections cannot respond to this message."

	| itemsToRemove |
	itemsToRemove := (aCollection == self)
		ifTrue: [aCollection copy]
		ifFalse: [aCollection].
	itemsToRemove do: [:element | self remove: element].
	^aCollection


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Cheers,

---==> Chris

PS>  Alexandre's example works just fine on VA Smalltalk, because the
underlying code calls #remove:ifAbsent: is a bit smarter.  The example fails
on VisualSmalltalk Enterprise, where it returns: OrderedCollection( 2 4 ).



More information about the Squeak-dev mailing list