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.11 date: 2023/05/25 00:02:38
user: cg
file: CollectingReadStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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.

copyright

COPYRIGHT (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.

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:

accessing
o  collection

o  readStream

instance creation
o  on: aStream collecting: aBlock

obsolete positioning
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) **

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

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

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)

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

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

stream protocol
o  position

o  position: newPos


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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 04:21:09 GMT