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