--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/CollectingReadStream.st Sat Dec 05 12:15:59 2009 +0100
@@ -0,0 +1,73 @@
+"{ Package: 'stx:libbasic2' }"
+
+Stream subclass:#CollectingReadStream
+ instanceVariableNames:'collectBlock inStream'
+ classVariableNames:''
+ poolDictionaries:''
+ category:'Streams'
+!
+
+!CollectingReadStream class methodsFor:'documentation'!
+
+documentation
+"
+ A stream which provides the result of applying a collectBlock
+ to the elements of an underlying stream.
+"
+!
+
+examples
+"
+ [exBegin]
+ |s|
+
+ s := CollectingReadStream
+ on:#(1 2 3 4 5 6 7 8) readStream
+ collecting:[:each | each squared].
+ s upToEnd
+ [exEnd]
+
+ [exBegin]
+ |s|
+
+ s := (#(1 2 3 4 5 6 7 8) readStream
+ selecting:[:n | n odd])
+ collecting:[:n | n squared].
+ s upToEnd
+ [exEnd]
+"
+! !
+
+!CollectingReadStream class methodsFor:'instance creation'!
+
+on:aStream collecting:aBlock
+ ^ self basicNew on:aStream collecting:aBlock
+! !
+
+!CollectingReadStream methodsFor:'instance creation'!
+
+on:aStream collecting:aBlock
+ inStream := aStream.
+ collectBlock := aBlock.
+! !
+
+!CollectingReadStream methodsFor:'queries'!
+
+atEnd
+ ^ inStream atEnd
+! !
+
+!CollectingReadStream methodsFor:'reading'!
+
+next
+ inStream atEnd ifTrue:[
+ ^ self pastEndRead
+ ].
+ ^ collectBlock value:(inStream next)
+! !
+
+!CollectingReadStream class methodsFor:'documentation'!
+
+version_CVS
+ ^ '$Header: /cvs/stx/stx/libbasic2/CollectingReadStream.st,v 1.1 2009-12-05 11:15:59 cg Exp $'
+! !