|
Class: ConsStream
Object
|
+--Stream
|
+--ConsStream
- Package:
- stx:libbasic2
- Category:
- Collections-Linked
- Version:
- rev:
1.7
date: 2023/11/24 13:50:54
- user: cg
- file: ConsStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
A read stream on a list (of conses)
Conses are not heavily used by Smalltalk (actually: not at all).
Consider this a demo class.
copyrightCOPYRIGHT (c) 2003 by eXept Software AG
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
-
on: aCons
-
accessing
-
list: something
-
reading
-
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
stream protocol-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
|list s|
list := Cons fromArray:#(1 2 3 4).
s := list readStream.
[s atEnd] whileFalse:[
Transcript showCR:(s next).
].
|
|gen allNumbers s|
gen := [:n | LazyCons car:n cdr:[ gen value:n+1 ]].
allNumbers := gen value:1.
s := allNumbers readStream.
100 timesRepeat:[
Transcript showCR:(s next).
].
|
|