author | Martin Kobetic |
Sun, 17 Nov 2013 00:21:39 -0500 | |
changeset 141 | 263190106319 |
parent 109 | 9587e2df7029 |
permissions | -rw-r--r-- |
9 | 1 |
"{ Package: 'stx:goodies/xtreams/terminals' }" |
2 |
||
3 |
"{ NameSpace: Xtreams }" |
|
4 |
||
5 |
ReadStream subclass:#BlockClosureReadStream |
|
6 |
instanceVariableNames:'contentsSpecies closeBlock' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
25
02e7c3b6f63c
added XtreamsPool to fix DefaultBufferSize; set proper category names
mkobetic
parents:
9
diff
changeset
|
9 |
category:'Xtreams-Terminals' |
9 | 10 |
! |
11 |
||
12 |
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. |
|
13 |
{{{ |
|
14 |
"inifinite stream of ones" |
|
15 |
[ 1 ] reading read: 20 |
|
16 |
}}} |
|
17 |
{{{ |
|
18 |
"Fibonacci" |
|
19 |
| a b | a := 0. b := 1. |
|
20 |
[ | x | x := a. a := b. b := x + a. x ] reading ++ 500; get |
|
21 |
}}} |
|
22 |
{{{ |
|
23 |
"Streaming over ObjectMemory" |
|
24 |
x := ObjectMemory someObject. |
|
25 |
[ x := ObjectMemory nextObjectAfter: x ] reading read: 5 |
|
26 |
}}} |
|
27 |
||
28 |
Instance Variables |
|
109 | 29 |
contentsSpecies <Class> species for collections of elements of this stream |
30 |
closeBlock <BlockClosure> invoked in response to the #close message, allows customizing the close behavior |
|
9 | 31 |
|
32 |
' |
|
33 |
! |
|
34 |
||
35 |
||
36 |
!BlockClosureReadStream methodsFor:'accessing'! |
|
37 |
||
38 |
get |
|
39 |
^source value |
|
40 |
! |
|
41 |
||
42 |
read: anInteger into: aSequenceableCollection at: startIndex |
|
43 |
| count | |
|
44 |
count := 0. |
|
45 |
[[count < anInteger] whileTrue: |
|
46 |
[aSequenceableCollection at: startIndex + count put: source value. |
|
47 |
count := count + 1]] |
|
48 |
on: Incomplete do: [(Incomplete on: aSequenceableCollection count: count at: startIndex) raise]. |
|
49 |
^anInteger |
|
50 |
! ! |
|
51 |
||
52 |
!BlockClosureReadStream methodsFor:'initialize-release'! |
|
53 |
||
54 |
close |
|
55 |
closeBlock cull: self |
|
56 |
! |
|
57 |
||
58 |
closeBlock |
|
59 |
^closeBlock |
|
60 |
! |
|
61 |
||
62 |
closeBlock: aBlock |
|
63 |
closeBlock := aBlock |
|
64 |
! |
|
65 |
||
66 |
contentsSpecies |
|
67 |
^contentsSpecies |
|
68 |
! |
|
69 |
||
70 |
contentsSpecies: anObject |
|
71 |
contentsSpecies := anObject |
|
72 |
! |
|
73 |
||
74 |
on: aBlockClosure |
|
75 |
super on: aBlockClosure. |
|
76 |
contentsSpecies := Array. |
|
77 |
closeBlock := [] |
|
78 |
! ! |
|
79 |
||
80 |
!BlockClosureReadStream class methodsFor:'documentation'! |
|
81 |
||
109 | 82 |
version_HG |
83 |
||
84 |
^ '$Changeset: <not expanded> $' |
|
9 | 85 |
! ! |
109 | 86 |