--- a/Collection.st Sat Jan 16 11:26:37 2010 +0000
+++ b/Collection.st Mon Feb 01 10:03:06 2010 +0000
@@ -736,6 +736,17 @@
"
#(1 2 3) third
"
+!
+
+values
+ "return a collection containing all values of the receiver.
+ This is to make value access to an OrderedDictionary compatible with any-Collection"
+
+ |aCollection|
+
+ aCollection := OrderedCollection new.
+ self do:[:value| aCollection add:value].
+ ^ aCollection
! !
!Collection methodsFor:'adding & removing'!
@@ -2379,34 +2390,39 @@
This method fails if neither the receiver nor aCollection is
a sequenceable collection (i.e. implements numeric key access)."
- |index "{ Class: SmallInteger }"
- newCollection|
+ |newCollection|
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 |
- newCollection add:(aTwoArgBlock value:(self at:index)
- value:element).
- index := index + 1
- ]
- ] ifTrue:[
- self do:[:element |
- newCollection add:(aTwoArgBlock value:element
- value:(aCollection at:index)).
- index := index + 1
- ]
+ self with:aCollection do:[:el1 :el2 |
+ newCollection add:(aTwoArgBlock value:el1 value:el2).
].
^ newCollection as:self species
"
(1 to:3) with:#(one two three) collect:[:num :sym | (num->sym)]
- #(1 2 3) with:#(10 20 30) collect:[:x :y | (x@y)]
+ #(1 2 3) with:#(10 20 30) collect:[:x :y | (x@y)]
+ "
+!
+
+with:aCollection count:aTwoArgBlock
+ "evaluate the argument, aBlock for successive elements from
+ each the receiver and the argument, aSequenceableCollection.
+ Count, how often the second argument, aTwoArgBlock returns true.
+ This method fails if neither the receiver nor aCollection is
+ a sequenceable collection (i.e. implements numeric key access)."
+
+ |count "{ Class: SmallInteger }"|
+
+ count := 0.
+ self with:aCollection do:[:el1 :el2 |
+ (aTwoArgBlock value:el1 value:el2) ifTrue:[
+ count := count + 1
+ ]
+ ].
+ ^ count
+
+ "
+ (1 to:3) with:#(1 3 3) count:[:n1 :n2 | n1 = n2]
"
!
@@ -3628,11 +3644,11 @@
!Collection class methodsFor:'documentation'!
version
- ^ '$Id: Collection.st 10494 2010-01-16 11:26:37Z vranyj1 $'
+ ^ '$Id: Collection.st 10496 2010-02-01 10:03:06Z vranyj1 $'
!
version_CVS
- ^ '§Header: /cvs/stx/stx/libbasic/Collection.st,v 1.239 2010/01/11 14:49:11 cg Exp §'
+ ^ '§Header: /cvs/stx/stx/libbasic/Collection.st,v 1.241 2010/01/29 16:41:43 cg Exp §'
! !
Collection initialize!
@@ -3641,3 +3657,4 @@
+