OrderedCollection.st
changeset 22319 abb4316c6bff
parent 22295 d47bb2912953
child 22392 3a8fce0e8d11
--- a/OrderedCollection.st	Sat Oct 21 17:04:03 2017 +0200
+++ b/OrderedCollection.st	Sun Oct 22 01:39:49 2017 +0200
@@ -312,7 +312,6 @@
 ! !
 
 
-
 !OrderedCollection methodsFor:'accessing'!
 
 at:anInteger
@@ -1372,6 +1371,30 @@
     ^ self copyFrom:1 to:self size
 !
 
+copyWithoutDuplicates
+    "return a new orderedCollection containing my entries,
+     but not any duplicates"
+
+    |newColl already|
+
+    already := Set new.
+    
+    newColl := self speciesForCollecting new.
+    self do:[:eachElement |
+        (already includes:eachElement) ifFalse:[
+            already add:eachElement.
+            newColl add:eachElement.
+        ]
+    ].
+    ^ newColl.
+
+    "
+     #(7 1 2 3 2 3 4 5 2 3 6 7 3 5 1) asOrderedCollection copyWithoutDuplicates
+    "
+
+    "Created: / 22-10-2017 / 01:39:25 / cg"
+!
+
 postCopy
     "have to copy the contentsArray too"