class: CollectingReadStream
authorClaus Gittinger <cg@exept.de>
Wed, 30 Apr 2014 20:19:37 +0200
changeset 3270 35d2087d156a
parent 3269 3f964738277d
child 3271 4a30a0fe6b25
class: CollectingReadStream added: #diverting:to: comment/format in: #documentation #on:collecting:
CollectingReadStream.st
--- a/CollectingReadStream.st	Wed Apr 30 13:03:07 2014 +0200
+++ b/CollectingReadStream.st	Wed Apr 30 20:19:37 2014 +0200
@@ -11,8 +11,14 @@
 
 documentation
 "
-    A stream which provides the result of applying a collectBlock
-    to the elements of an underlying stream. 
+    A stream which evaluates collectBlock for every element
+    read from an underlying stream, providing the result from
+    the evaluation as read-elements.
+    Useful to process a readStream, for tracing or diverting to another
+    processing stage.
+
+    [Author:]
+        Claus Gittinger
 "
 !
 
@@ -40,8 +46,30 @@
 
 !CollectingReadStream class methodsFor:'instance creation'!
 
+diverting:aStream to:anotherStream
+    ^ self on:aStream collecting:[:el | anotherStream nextPut:el. el].
+
+    "
+     |s|
+
+     s := CollectingReadStream 
+            diverting:#(1 2 3 4 5 6 7 8) readStream
+            to:Transcript.
+     s upToEnd  
+    "
+!
+
 on:aStream collecting:aBlock
     ^ self basicNew on:aStream collecting:aBlock
+
+    "
+     |s|
+
+     s := CollectingReadStream 
+            on:#(1 2 3 4 5 6 7 8) readStream
+            collecting:[:each | each squared].
+     s upToEnd  
+    "
 ! !
 
 !CollectingReadStream methodsFor:'instance creation'!
@@ -134,6 +162,6 @@
 !CollectingReadStream class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic2/CollectingReadStream.st,v 1.5 2013-08-18 10:56:38 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/CollectingReadStream.st,v 1.6 2014-04-30 18:19:37 cg Exp $'
 ! !