eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'CollectingReadStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: CollectingReadStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--CollectingReadStream

Package:
stx:libbasic2
Category:
Streams-Misc
Version:
rev: 1.7 date: 2017/02/15 21:13:36
user: cg
file: CollectingReadStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


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.


Class protocol:

instance creation
o  diverting: aStream to: anotherStream
|s|

s := CollectingReadStream
diverting:#(1 2 3 4 5 6 7 8) readStream
to:Transcript.
s upToEnd

o  on: aStream collecting: aBlock
|s|

s := CollectingReadStream
on:#(1 2 3 4 5 6 7 8) readStream
collecting:[:each | each squared].
s upToEnd


Instance protocol:

instance creation
o  on: aStream collecting: aBlock

queries
o  atEnd

o  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)

stream protocol
o  next

o  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.

o  nextPeek
(comment from inherited method)
advance to next element and return the peeked element

o  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

o  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.

o  position

o  position0Based

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  position1Based

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  readStream


Examples:


    |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    


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sat, 21 Jul 2018 07:44:55 GMT