first: n
no longer raise an error, if not enough elements are
present; instead, return what we have.
--- a/Collection.st Sat Mar 28 09:55:27 2015 +0100
+++ b/Collection.st Sat Mar 28 09:55:33 2015 +0100
@@ -277,6 +277,7 @@
^ self newWithSize:n
! !
+
!Collection class methodsFor:'Signal constants'!
emptyCollectionSignal
@@ -318,13 +319,6 @@
"Created: / 09-01-2011 / 10:37:15 / cg"
! !
-!Collection class methodsFor:'misc ui support'!
-
-iconInBrowserSymbol
- <resource: #programImage>
-
- ^ #containerClassBrowserIcon
-! !
!Collection class methodsFor:'queries'!
@@ -534,6 +528,7 @@
"Created: / 22-10-2008 / 21:29:27 / cg"
! !
+
!Collection methodsFor:'accessing'!
anElement
@@ -640,9 +635,11 @@
first:n
"return the n first elements of the collection.
- Raises an error if there are not enough elements in the receiver.
+ No longer raises an error if there are not enough elements;
+ instead, returns what is there.
+
For unordered collections, this simply returns the first
- n elements when enumerating them
+ n elements when enumerating them.
(Warning: the contents of the returned collection is not deterministic in this case).
This should be redefined in subclasses."
@@ -659,13 +656,18 @@
^ coll
].
].
-
- "error if collection has not enough elements"
- ^ self notEnoughElementsError
+ "/ OLD:
+ "/ "error if collection has not enough elements"
+ "/ ^ self notEnoughElementsError
+ "/ NEW:
+ "/ return what we have - no error if not enough elements
+ ^ coll.
"
#(1 2 3 4 5) first:3
#(1 2 3 4 5) asSet first:3
+ #(1 2 3) first:5
+ #(1 2 3) asSet first:5
"
"Modified (format): / 29-09-2011 / 10:16:49 / cg"
@@ -5737,14 +5739,15 @@
^ aVisitor visitCollection:self with:aParameter
! !
+
!Collection class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.359 2015-03-02 12:12:24 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.360 2015-03-28 08:55:33 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.359 2015-03-02 12:12:24 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.360 2015-03-28 08:55:33 cg Exp $'
! !