Collection.st
changeset 11469 d1344e7b8364
parent 11468 1a5264854d15
child 11470 020075295c68
--- a/Collection.st	Fri Jan 16 13:52:27 2009 +0100
+++ b/Collection.st	Fri Jan 16 13:53:46 2009 +0100
@@ -1020,8 +1020,8 @@
 
     self emptyCheck.
     ^ self 
-                inject:(self first class unity)
-                 into:[:accum :each | accum * each].
+        inject:(self first class unity)
+        into:[:accum :each | accum * each].
 
     "
      TestCase should:[ Array new sum ] raise:Error.
@@ -1211,23 +1211,34 @@
     ^ self addAllTo:(OrderedCollection new:self size)
 !
 
-select:aBlock
-    "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.
-    self do:[:each |
-        (aBlock value:each) ifTrue:[newCollection add:each].
-    ].
-    ^ newCollection
+asRunArray
+    "return a new RunArray with the collections elements"
+
+    ^ RunArray from:self.
+
+"/    |runs lastElement occurrences|
+"/
+"/    runs := RunArray new.
+"/    occurrences := 0.
+"/    self do:[:each |
+"/        each == lastElement ifTrue:[
+"/            occurrences := occurrences + 1
+"/        ] ifFalse:[
+"/            runs add:lastElement withOccurrences:occurrences.
+"/            occurrences := 1.
+"/            lastElement := each
+"/        ].
+"/    ].
+"/    occurrences ~~ 0 ifTrue:[
+"/        runs add:lastElement withOccurrences:occurrences
+"/    ].
+"/    ^ runs
 
     "
-     #(1 2 3 4) select:[:e | e odd]   
-     (1 to:10) select:[:e | e even]     
+     #(1 2 3 3 3 4 4 4 4 5 6 7) asRunArray 
     "
+
+    "Modified: / 7.4.1998 / 09:50:54 / cg"
 !
 
 asSequenceableCollection
@@ -3350,7 +3361,7 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.213 2009-01-16 12:52:27 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.214 2009-01-16 12:53:46 cg Exp $'
 ! !
 
 Collection initialize!