"{ Package: 'stx:goodies/xtreams/terminals' }"
"{ NameSpace: Xtreams }"
ReadStream subclass:#BlockClosureReadStream
instanceVariableNames:'contentsSpecies closeBlock'
classVariableNames:''
poolDictionaries:''
category:'Xtreams-Terminals'
!
BlockClosureReadStream comment:'Read stream on a zero argument block, evaluates the block once for each requested element, the result of the block evaluation is the element.
{{{
"inifinite stream of ones"
[ 1 ] reading read: 20
}}}
{{{
"Fibonacci"
| a b | a := 0. b := 1.
[ | x | x := a. a := b. b := x + a. x ] reading ++ 500; get
}}}
{{{
"Streaming over ObjectMemory"
x := ObjectMemory someObject.
[ x := ObjectMemory nextObjectAfter: x ] reading read: 5
}}}
Instance Variables
contentsSpecies <Class> species for collections of elements of this stream
closeBlock <BlockClosure> invoked in response to the #close message, allows customizing the close behavior
'
!
!BlockClosureReadStream methodsFor:'accessing'!
get
^source value
!
read: anInteger into: aSequenceableCollection at: startIndex
| count |
count := 0.
[[count < anInteger] whileTrue:
[aSequenceableCollection at: startIndex + count put: source value.
count := count + 1]]
on: Incomplete do: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise].
^anInteger
! !
!BlockClosureReadStream methodsFor:'initialize-release'!
close
closeBlock cull: self
!
closeBlock
^closeBlock
!
closeBlock: aBlock
closeBlock := aBlock
!
contentsSpecies
^contentsSpecies
!
contentsSpecies: anObject
contentsSpecies := anObject
!
on: aBlockClosure
super on: aBlockClosure.
contentsSpecies := Array.
closeBlock := []
! !
!BlockClosureReadStream class methodsFor:'documentation'!
version_HG
^ '$Changeset: <not expanded> $'
! !