added #last and #last:
authorClaus Gittinger <cg@exept.de>
Tue, 10 Jul 2001 12:06:56 +0200
changeset 5888 64d077a702c7
parent 5887 803c3ff82afe
child 5889 171985b0ea2f
added #last and #last:
WriteStream.st
--- a/WriteStream.st	Tue Jul 10 12:02:29 2001 +0200
+++ b/WriteStream.st	Tue Jul 10 12:06:56 2001 +0200
@@ -124,6 +124,46 @@
     "Modified: / 30.10.1997 / 16:21:23 / cg"
 !
 
+last
+    "return the last element - report an error if the stream is empty"
+
+    ^ collection at:(position - 1).
+
+    "
+     |s|
+
+     s := '' writeStream.
+     s nextPut:$a.
+     s last.       
+     s nextPut:$b.
+     s last.        
+     s nextPut:$c.
+     s last.        
+    "
+!
+
+last:n
+    "return the last n elements as species of the underlying collection;
+     Report an error if the stream is empty"
+
+    ^ collection copyFrom:(position - n) to:(position - 1).
+
+    "
+     |s|
+
+     s := '' writeStream.
+     s nextPut:$a.
+     s last:1.       
+     s nextPut:$b.
+     s last:1.        
+     s last:2.        
+     s nextPut:$c.
+     s last:1.        
+     s last:2.        
+     s last:3.        
+    "
+!
+
 reset
     "reset the stream; write anew.
      See the comment in WriteStream>>contents"
@@ -437,5 +477,5 @@
 !WriteStream class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.44 2000-08-22 13:49:36 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.45 2001-07-10 10:06:56 cg Exp $'
 ! !