terminals/Xtreams__BlockClosureWriteStream.st
author Martin Kobetic
Sun, 17 Nov 2013 00:22:31 -0500
changeset 144 e193a6772be4
parent 109 9587e2df7029
permissions -rw-r--r--
merging

"{ Package: 'stx:goodies/xtreams/terminals' }"

"{ NameSpace: Xtreams }"

WriteStream subclass:#BlockClosureWriteStream
	instanceVariableNames:'contentsSpecies closeBlock'
	classVariableNames:''
	poolDictionaries:''
	category:'Xtreams-Terminals'
!

BlockClosureWriteStream comment:'Write stream on a single argument block, the block is evaluated for each element written with the element assigned as the argument of the evaluation.
{{{
	"Transcript as an xtream"
	[ :x | Transcript nextPut: x ] writing write: ''Hello World!!''
}}}
{{{
	"/dev/null"
	[ :x | ] writing write: ''Hello World!!''
}}}

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

'
!


!BlockClosureWriteStream methodsFor:'accessing'!

write: anInteger from: aSequenceableCollection at: startIndex
	| count |
	count := 0.
	[[count < anInteger] whileTrue:
		[destination value: (aSequenceableCollection at: startIndex + count).
		count := count + 1]]
			on: Incomplete do: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise].
	^anInteger
! !

!BlockClosureWriteStream methodsFor:'initialize-release'!

close
	closeBlock cull: self
!

closeBlock
	^closeBlock
!

closeBlock: aBlock
	closeBlock := aBlock
!

contentsSpecies
	^contentsSpecies
!

contentsSpecies: anObject
	contentsSpecies := anObject
!

flush
!

on: aBlockClosure
	super on: aBlockClosure.
	contentsSpecies := Array.
	closeBlock := []
! !

!BlockClosureWriteStream class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !