can be defined on Collection since it does not work on Array. Now extending Collection that way produce non API polymorphic objects! Defining a new class with specializing add: is MUCH better because of that exact purpose. Please do not propose to extend Collection with method only working for a subset we have enough to them On Dec 23, 2009, at 10:55 PM, Adrian Kuhn wrote:
Stéphane Ducasse <stephane.ducasse@...> writes:
I was more looking at the user perspective. You often want an orderedCollection (add:) vs Array at: but which deals with duplicate as a Set.
A simple method should do that job
Collection >> #addIfAbsent: element (self includes: element) ifFalse: [ self add: element ]
usage
coll := OrderedCollection new. coll addIfAbsent: #foo. coll addIfAbsent: #bar. coll addIfAbsent: #qux. coll addIfAbsent: #bar. self assert: coll asArray = #(foo bar qux).
--AA
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project