--- a/Collection.st Wed Feb 04 18:35:14 2015 +0100
+++ b/Collection.st Wed Feb 04 20:35:49 2015 +0100
@@ -275,6 +275,7 @@
^ self newWithSize:n
! !
+
!Collection class methodsFor:'Signal constants'!
emptyCollectionSignal
@@ -532,6 +533,7 @@
"Created: / 22-10-2008 / 21:29:27 / cg"
! !
+
!Collection methodsFor:'accessing'!
anElement
@@ -2451,6 +2453,27 @@
"
!
+collectWithIndex:aTwoArgBlock
+ "for each element in the receiver and a running index,
+ evaluate the argument, aTwoArgBlock.
+ Return a new collection with the results"
+
+ |newCollection runIndex|
+
+ newCollection := self species new.
+ runIndex := 1.
+ self do:[:element |
+ newCollection add:(aTwoArgBlock value:element value:runIndex).
+ runIndex := runIndex + 1.
+ ].
+ ^ newCollection
+
+ "
+ #(1 2 3 4) collectWithIndex:[:n :i | n * 2 + i]
+ #(1 2 3 4) collectWithIndex:[:n :i | i -> (n * 2)]
+ "
+!
+
count:aBlock
"count elements, for which aBlock returns true.
Return the sum."
@@ -5665,11 +5688,11 @@
!Collection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.355 2015-02-03 14:21:50 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.356 2015-02-04 19:35:49 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.355 2015-02-03 14:21:50 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.356 2015-02-04 19:35:49 cg Exp $'
! !