ConsStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5249 08af43aaea4c
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:

"
 COPYRIGHT (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.
"
"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

Stream subclass:#ConsStream
	instanceVariableNames:'list'
	classVariableNames:''
	poolDictionaries:''
	category:'Collections-Linked'
!

!ConsStream class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (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.
"
!

documentation
"
    A stream on a list (of conses)
    Conses are not heavily used by Smalltalk (actually: not at all).
    Consider this a demo class.

    [author:]
        Claus Gittinger (Dec 2003)

    [see also:]

"
!

examples
"
                                                                            [exBegin]
    |list s|

    list := Cons fromArray:#(1 2 3 4).   
    s := list readStream.
    [s atEnd] whileFalse:[
        Transcript showCR:(s next).
    ].
                                                                            [exEnd]
                                                                            [exBegin]
    |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).
    ].
                                                                            [exEnd]
"
! !

!ConsStream class methodsFor:'instance creation'!

on:aCons
    ^ self basicNew list:aCons
! !

!ConsStream methodsFor:'accessing'!

list:something
    list := something.
! !

!ConsStream methodsFor:'reading'!

atEnd
    ^ list isNil 
! !

!ConsStream methodsFor:'stream protocol-reading'!

next
    |rslt|

    list isNil ifTrue:[
        ^ self pastEndRead
    ].
    rslt := list car.
    list := list cdr.
    ^ rslt
! !

!ConsStream class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !