diff -r 38782bff886a -r 6c38ca59927f SequenceableCollection.st --- a/SequenceableCollection.st Thu May 12 04:07:15 1994 +0200 +++ b/SequenceableCollection.st Tue May 17 12:09:46 1994 +0200 @@ -26,7 +26,7 @@ an index. SequenceableCollection is an abstract class - there are no instances of it in the system. -$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.10 1994-03-30 09:41:04 claus Exp $ +$Header: /cvs/stx/stx/libbasic/SequenceableCollection.st,v 1.11 1994-05-17 10:08:55 claus Exp $ written spring 89 by claus '! @@ -98,6 +98,18 @@ concrete implementations must define this" ^ self subclassResponsibility +! + +keys + "return a collection with all keys in the Smalltalk dictionary" + + |sz| + + sz := self size. + sz == 0 ifTrue:[ + ^ #() + ]. + ^ 1 to:sz ! ! !SequenceableCollection methodsFor:'comparing'! @@ -1164,6 +1176,8 @@ end "{ Class: SmallInteger }" smallest thisOne| + "this is just a q&d hack - there must be better implementations for this ;-)" + end := self size. 1 to:end do:[:index | smallest := self at:index. @@ -1184,9 +1198,9 @@ ] " - #(1 16 7 98 3 19 4 0) topologicalSort:[:a :b | a < b] - #(1 16 7 98 3 19 4 0) sort:[:a :b | a < b] - Smalltalk allClasses asArray topologicalSort:[:a :b | b isSubclassOf:a] + #(1 16 7 98 3 19 4 0) topologicalSort:[:a :b | a < b] Array(0 1 3 4 7 16 19 98) + #(1 16 7 98 3 19 4 0) sort:[:a :b | a < b] Array(0 1 3 4 7 16 19 98) + Smalltalk allClasses asArray topologicalSort:[:a :b | b isSubclassOf:a] " ! @@ -1272,6 +1286,9 @@ 1 to:stop do:[:index | aBlock value:(self at:index). ] + " + #(one two three four five six) do:[:element | Transcript showCr:element] + " ! keysAndValuesDo:aTwoArgBlock @@ -1284,6 +1301,26 @@ 1 to:stop do:[:index | aTwoArgBlock value:index value:(self at:index). ] + " + #(one two three four five six) keysAndValuesDo:[:key :element | Transcript show:key; space; showCr:element] + " +! + +with:aSequenceableCollection do:aTwoArgBlock + "evaluate the argument, aBlock for successive elements from + each the receiver and the argument, aSequenceableCollection. + The second argument, aBlock must be a two-argument block. + The collection argument must implement access via a numeric key." + + |stop "{ Class: SmallInteger }" | + + stop := self size. + 1 to:stop do:[:index | + aTwoArgBlock value:(self at:index) value:(aSequenceableCollection at:index). + ] + " + #(one two three four five six) with:(1 to:10) do:[:el1 :el2 | Transcript show:el1; space; showCr:el2] + " ! from:index1 to:index2 do:aBlock @@ -1298,6 +1335,10 @@ start to:stop do:[:index | aBlock value:(self at:index). ] + + " + #(one two three four five six) from:3 to:5 do:[:element | Transcript showCr:element] + " ! from:index1 to:index2 reverseDo:aBlock @@ -1312,19 +1353,10 @@ stop to:start by:-1 do:[:index | aBlock value:(self at:index). ] -! -with:aCollection do:aTwoArgBlock - "evaluate the argument, aBlock for successive elements from - each of the two collections self and aCollection. - aBlock must be a two-argument block" - - |stop "{ Class: SmallInteger }" | - - stop := self size. - 1 to:stop do:[:index | - aTwoArgBlock value:(self at:index) value:(aCollection at:index). - ] + " + #(one two three four five six) from:3 to:5 reverseDo:[:element | Transcript showCr:element] + " ! reverseDo:aBlock @@ -1337,6 +1369,9 @@ sz to:1 by:-1 do:[:index | aBlock value:(self at:index). ] + " + #(one two three four five six) reverseDo:[:element | Transcript showCr:element] + " ! collect:aBlock @@ -1352,6 +1387,9 @@ newCollection at:index put:(aBlock value:(self at:index)). ]. ^ newCollection + " + #(one two three four five six) collect:[:element | element asUppercase] + " ! select:aBlock @@ -1371,4 +1409,7 @@ ]. ]. ^ newColl + " + #(one two three four five six) select:[:element | element startsWith:'f'] + " ! !