last: n
authorClaus Gittinger <cg@exept.de>
Sat, 28 Mar 2015 10:01:50 +0100
changeset 17704 22b570284f10
parent 17703 9a1969dcbeb3
child 17705 76b6ce4a59cd
last: n no longer raise an error, if not enough elements are present; instead, return what we have. (VW compat.)
Collection.st
--- a/Collection.st	Sat Mar 28 10:01:41 2015 +0100
+++ b/Collection.st	Sat Mar 28 10:01:50 2015 +0100
@@ -743,7 +743,8 @@
 
 last:n
     "return the n last 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 last
      n elements when enumerating them 
      (Warning: the contents of the returned collection is not deterministic in this case).
@@ -764,16 +765,19 @@
         coll add:e.
     ].
 
-    remain ~~ 0 ifTrue:[
-        "error if collection has not enough elements"
-        ^ self notEnoughElementsError
-    ].
+    "/ OLD:
+    "/ remain ~~ 0 ifTrue:[
+    "/     "error if collection has not enough elements"
+    "/     ^ self notEnoughElementsError
+    "/ ].
     ^ coll
 
     "
      #(1 2 3 4 5) last:3           
      #(1 2 3 4 5 6 7 8 9 0) asSet last:3           
      'hello world' last:5           
+     'hello' last:10           
+     'hello' asSet last:10           
     "
 
     "Modified (format): / 29-09-2011 / 10:16:22 / cg"
@@ -5743,11 +5747,11 @@
 !Collection class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.360 2015-03-28 08:55:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.361 2015-03-28 09:01:50 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.360 2015-03-28 08:55:33 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Collection.st,v 1.361 2015-03-28 09:01:50 cg Exp $'
 ! !