--- a/Collection.st Sun Aug 01 12:11:07 2010 +0100
+++ b/Collection.st Tue Aug 10 09:55:15 2010 +0100
@@ -901,7 +901,7 @@
!
removeAll:aCollection
- "remove all elements of the argument, aCollection from the receiver.
+ "remove all elements from the receiver which are equal to any in aCollection.
Return the argument, aCollection.
Raises an error, if some element-to-remove is not in the receiver.
(see also: #removeAllFoundIn:, which does not raise an error).
@@ -939,12 +939,11 @@
coll
"
-
+ "Modified: / 05-08-2010 / 13:50:33 / cg"
!
removeAllFoundIn:aCollection
- "Remove each element of aCollection, which is present in the receiver
- from the receiver.
+ "remove all elements from the receiver which are equal to any in aCollection.
No error is raised, if some element-to-remove is not in the receiver.
(see also: #removeAll:, which does raise an error)."
@@ -967,6 +966,76 @@
coll
"
+ "Modified: / 05-08-2010 / 13:51:05 / cg"
+!
+
+removeAllIdentical:aCollection
+ "remove all elements from the receiver which are in aCollection.
+ Return the argument, aCollection.
+ Raises an error, if some element-to-remove is not in the receiver.
+ (see also: #removeAllFoundIn:, which does not raise an error).
+
+ Notice: for some collections (those not tuned for
+ resizing themself) this may be very slow.
+ If the number of removed elements is big compared to to
+ the receivers size, it may be better to copy the
+ ones which are not to be removed into a new collection."
+
+ aCollection do:[:element | self removeIdentical:element].
+ ^ aCollection
+
+ "
+ |coll|
+
+ coll := #(1 2 3 4 5 6) asSet.
+ coll removeAll:#(4 5 6).
+ coll
+ "
+
+ "raises an error:
+ |coll|
+
+ coll := #(1 2 3 4 5 6) asSet.
+ coll removeAll:#(4 5 6 7 8).
+ coll
+ "
+
+ "no error raised:
+ |coll|
+
+ coll := #(1 2 3 4 5 6) asSet.
+ coll removeAllFoundIn:#(4 5 6 7 8).
+ coll
+ "
+
+ "Created: / 05-08-2010 / 13:51:51 / cg"
+!
+
+removeAllIdenticalFoundIn:aCollection
+ "remove all elements from the receiver which are in aCollection.
+ No error is raised, if some element-to-remove is not in the receiver.
+ (see also: #removeAll:, which does raise an error)."
+
+ aCollection do:[:each | self removeIdentical:each ifAbsent:[]].
+ ^ aCollection
+
+ "
+ |coll|
+
+ coll := #(1 2 3 4 5 6) asSet.
+ coll removeAllFoundIn:#(4 5 6 7 8).
+ coll
+ "
+
+ "raises an error:
+ |coll|
+
+ coll := #(1 2 3 4 5 6) asSet.
+ coll removeAll:#(4 5 6 7 8).
+ coll
+ "
+
+ "Created: / 05-08-2010 / 13:52:21 / cg"
!
removeAllKeys:aCollection
@@ -2300,18 +2369,35 @@
the argument aBlock evaluates to true.
See also: #removeAllFoundIn: and #removeAllSuchThat:"
+ ^ self select:aBlock as:(self species)
+
+ "
+ #(1 2 3 4) select:[:e | e odd]
+ (1 to:10) select:[:e | e even]
+ "
+
+ "Modified: / 07-08-2010 / 16:26:40 / cg"
+!
+
+select:aBlock as:aCollectionClass
+ "return a new collection with all elements from the receiver, for which
+ the argument aBlock evaluates to true.
+ See also: #removeAllFoundIn: and #removeAllSuchThat:"
+
|newCollection|
- newCollection := self species new.
+ newCollection := aCollectionClass new.
self do:[:each |
(aBlock value:each) ifTrue:[newCollection add:each].
].
^ newCollection
"
- #(1 2 3 4) select:[:e | e odd]
- (1 to:10) select:[:e | e even]
+ #(1 2 3 4) select:[:e | e odd] as:OrderedCollection
+ (1 to:10) select:[:e | e even] as:OrderedCollection
"
+
+ "Created: / 07-08-2010 / 16:26:15 / cg"
!
select:aBlock ifNone:exceptionBlock
@@ -3650,18 +3736,19 @@
!Collection class methodsFor:'documentation'!
version
- ^ '$Id: Collection.st 10544 2010-07-12 16:20:36Z vranyj1 $'
+ ^ '$Id: Collection.st 10564 2010-08-10 08:55:15Z vranyj1 $'
!
version_CVS
- ^ 'Header: /cvs/stx/stx/libbasic/Collection.st,v 1.244 2010/07/11 15:06:50 cg Exp '
+ ^ 'Header: /cvs/stx/stx/libbasic/Collection.st,v 1.246 2010/08/07 17:18:25 cg Exp '
!
version_SVN
- ^ '$Id: Collection.st 10544 2010-07-12 16:20:36Z vranyj1 $'
+ ^ '$Id: Collection.st 10564 2010-08-10 08:55:15Z vranyj1 $'
! !
Collection initialize!
+