|
Class: ConsStream
Object
|
+--Stream
|
+--ConsStream
- Package:
- stx:libbasic2
- Category:
- Collections-Linked
- Version:
- rev:
1.4
date: 2011/09/27 09:42:44
- user: cg
- file: ConsStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger (Dec 2003)
A stream on a list (of conses)
Conses are not heavily used by Smalltalk (actually: not at all).
Consider this a demo class.
instance creation
-
on: aCons
-
accessing
-
list: something
-
reading
-
atEnd
-
-
next
-
|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).
].
|
|