|
Class: CollectingReadStream
Object
|
+--Stream
|
+--PeekableStream
|
+--CollectingReadStream
- Package:
- stx:libbasic2
- Category:
- Streams-Misc
- Version:
- rev:
1.11
date: 2023/05/25 00:02:38
- user: cg
- file: CollectingReadStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
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.
copyrightCOPYRIGHT (c) 2009 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
diverting: aStream to: anotherStream
-
|s|
s := CollectingReadStream
diverting:#(1 2 3 4 5 6 7 8) readStream
to:Transcript.
s upToEnd
-
on: aStream collecting: aBlock
-
|s|
s := CollectingReadStream
on:#(1 2 3 4 5 6 7 8) readStream
collecting:[:each | each squared].
s upToEnd
accessing
-
collection
-
-
readStream
-
instance creation
-
on: aStream collecting: aBlock
-
obsolete positioning
-
position0Based
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
position1Based
-
** This is an obsolete interface - do not use it (it may vanish in future versions) **
queries
-
atEnd
-
(comment from inherited method)
return true if the end of the stream has been reached;
- we do not know here how to do it, it must be redefined in subclass
-
contents
-
(comment from inherited method)
return a collection of the elements up-to the end.
Return an empty collection, if the stream is already at the end.
-
contentsSpecies
-
return a class of which instances will be returned, when
parts of the collection are asked for.
(see upTo-kind of methods in Stream)
reading
-
next
-
(comment from inherited method)
return the next element of the stream
- we do not know here how to do it, it must be redefined in subclass
-
nextOrNil
-
(comment from inherited method)
like #next, this returns the next element, if available.
If nothing is available, this does never raise a read-beyond end signal.
Instead, nil is returned immediately.
-
peek
-
(comment from inherited method)
return the next element of the stream without advancing (i.e.
the following send of next will return this element again.)
- we do not know here how to do it, it must be redefined in subclass
-
peekOrNil
-
(comment from inherited method)
like #peek, this returns the next readAhead element, if available.
However, unlike #peek, this does not raise an atEnd-query signal - even
if handled. Instead, nil is returned immediately.
stream protocol
-
position
-
-
position: newPos
-
|s|
s := CollectingReadStream
on:#(1 2 3 4 5 6 7 8) readStream
collecting:[:each | each squared].
s upToEnd
|
|s|
s := (#(1 2 3 4 5 6 7 8) readStream
selecting:[:n | n odd])
collecting:[:n | n squared].
s upToEnd
|
|