+#speciesForAdding; better #collect:with: for fixed size collections
authorClaus Gittinger <cg@exept.de>
Wed, 15 May 2002 10:04:35 +0200
changeset 6547 86e092527dd1
parent 6546 9cada8214da7
child 6548 e47779f9bbfa
+#speciesForAdding; better #collect:with: for fixed size collections
Collection.st
--- a/Collection.st	Tue May 14 14:38:26 2002 +0200
+++ b/Collection.st	Wed May 15 10:04:35 2002 +0200
@@ -1671,10 +1671,12 @@
     |index  "{ Class: SmallInteger }" 
      newCollection|
 
-    newCollection := self species new.
+    newCollection := self speciesForAdding new.
+
     index := 1.
     aCollection isSequenceable ifFalse:[
         self isSequenceable ifFalse:[
+            "/ mhmh - could use two streams here...
             ^ self error:'neither collection is sequenceable'.
         ].
         aCollection do:[:element |
@@ -1689,10 +1691,10 @@
             index := index + 1
         ]
     ].
-    ^ newCollection
+    ^ newCollection as:self species
 
     "
-     (1 to:3) with:#(one two three) collect:[:num :sym | (num->sym)]
+     (1 to:3) with:#(one two three) collect:[:num :sym | (num->sym)] 
      #(1 2 3) with:#(10 20 30) collect:[:x :y | (x@y)]
     "
 !
@@ -2200,6 +2202,13 @@
         count := count + 1
     ].
     ^ count
+!
+
+speciesForAdding
+     "like species, but redefined for collections which cannot grow easily.
+      Used by functions which create a growing collection (see collect:with:, for example)"
+
+    ^ self species
 ! !
 
 !Collection methodsFor:'testing'!
@@ -2374,6 +2383,6 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.123 2002-05-02 08:46:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.124 2002-05-15 08:04:35 cg Exp $'
 ! !
 Collection initialize!