Define #intersect:
authorStefan Vogel <sv@exept.de>
Fri, 15 Sep 2000 12:31:31 +0200
changeset 5608 35df47851fe7
parent 5607 94c690ba0dea
child 5609 7ecaa8d824fe
Define #intersect:
Set.st
--- a/Set.st	Fri Sep 15 12:30:55 2000 +0200
+++ b/Set.st	Fri Sep 15 12:31:31 2000 +0200
@@ -894,6 +894,35 @@
     "
      #(0 1 2 3 4 5 6 7 8 9) asSet - #(1 2 3)   
     "
+!
+
+intersect:aCollection
+    "return a new set containing all elements of the receiver, which are
+     also contained in the argument collection"
+
+    |newCollection|
+
+    newCollection := self species new.
+    aCollection do:[:element |
+        (self includes:element) ifTrue:[
+            newCollection add:element
+        ]
+    ].
+    ^ newCollection
+
+    "
+     #(0 1 2 3 4 5 6 7 8 9) asSet intersect:#(1 2 3 11)   
+    "
+
+
+
+
+
+
+
+
+
+
 ! !
 
 !Set methodsFor:'testing'!
@@ -991,6 +1020,6 @@
 !Set class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.66 2000-08-30 21:24:57 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Set.st,v 1.67 2000-09-15 10:31:31 stefan Exp $'
 ! !
 Set initialize!