--- a/Collection.st Sun Jul 23 13:54:53 1995 +0200
+++ b/Collection.st Thu Jul 27 06:01:12 1995 +0200
@@ -22,7 +22,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.36 1995-07-22 19:21:51 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.37 1995-07-27 03:59:53 claus Exp $
'!
!Collection class methodsFor:'documentation'!
@@ -43,7 +43,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.36 1995-07-22 19:21:51 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.37 1995-07-27 03:59:53 claus Exp $
"
!
@@ -250,7 +250,7 @@
copyEmpty:size
"return a copy of the receiver with no elements, but space for
- size elements. This is used by copying and enumertion methods
+ size elements. This is used by copying and enumeration methods
to get a new instance which is similar to the receiver.
This method should be redefined in subclasses with instance
variables, which should be put into the copy too.
@@ -262,7 +262,7 @@
copyEmpty
"return a copy of the receiver with no elements.
- This is used by copying and enumertion methods
+ This is used by copying and enumeration methods
to get a new instance which is similar to the receiver."
^ self species new
@@ -270,7 +270,7 @@
copyEmptyAndGrow:size
"return a copy of the receiver with size nil elements.
- This is used by copying and enumertion methods
+ This is used by copying and enumeration methods
to get a new instance which is similar to the receiver."
^ (self copyEmpty:size) grow:size
@@ -876,6 +876,21 @@
^ true
!
+count:aBlock
+ "count elements, for which aBlock returns true.
+ Return the sum."
+
+ ^ self inject:0 into:[:sumSoFar :element |
+ (aBlock value:element) ifTrue:[sumSoFar + 1]
+ ifFalse:[sumSoFar]
+ ]
+
+ "
+ #(1 2 3 4 6 8 10) count:[:a | a even]
+ #(1 nil nil nil 2 3 nil 4 5) count:[:a | a isNil]
+ "
+!
+
addAllTo:aCollection
"add all elements of the receiver, to aCollection.
Return aCollection."