Collection.st
changeset 12345 63ef3a0f6a62
parent 12292 5d5c2bc66cc0
child 12347 d67d6827d22a
--- a/Collection.st	Mon Oct 26 14:27:03 2009 +0100
+++ b/Collection.st	Mon Oct 26 15:45:40 2009 +0100
@@ -228,7 +228,6 @@
     ^ self withSize:n
 ! !
 
-
 !Collection class methodsFor:'Signal constants'!
 
 emptyCollectionSignal
@@ -333,6 +332,35 @@
     "
 !
 
+gather:aBlock
+    "return an Array,
+     containing all elements as returned from applying aBlock to each element if the receiver,
+     where the block returns a collection of to-be-added elements.
+     This could also be called: collectAllAsArray:"
+
+    ^ self gather:aBlock as:Array
+
+    "
+     (Set withAll:#(10 20 30 10 20 40)) gather:[:el | Array with:el with:el * 2]
+    "
+!
+
+gather:aBlock as:aClass
+    "return an instance of the collection-class aClass,
+     containing all elements as returned from applying aBlock to each element if the receiver.
+     where the block returns a collection of to-be-added elements.
+     This could also be called: collectAll:as:"
+
+    ^ aClass streamContents:[:s |
+        self do: [:ea | s nextPutAll: (aBlock value: ea)]
+    ]
+
+    "
+     (Set withAll:#(10 20 30 10 20 40)) gather:[:el | Array with:el with:el * 2] as:OrderedCollection
+     (Set withAll:#(10 20 30 10 20 40)) collectAll:[:el | Array with:el with:el * 2]
+    "
+!
+
 groupBy:keyBlock having:selectBlock 
     "Like in SQL operation - Split the recievers contents into collections of 
      elements for which keyBlock returns the same results, and return those 
@@ -402,7 +430,6 @@
     ].
 ! !
 
-
 !Collection methodsFor:'accessing'!
 
 anElement
@@ -3560,11 +3587,11 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.233 2009-10-19 10:21:32 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.234 2009-10-26 14:45:40 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.233 2009-10-19 10:21:32 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.234 2009-10-26 14:45:40 cg Exp $'
 ! !
 
 Collection initialize!