2363
|
1 |
"{ Package: 'stx:libbasic2' }"
|
|
2 |
|
|
3 |
Stream subclass:#CollectingReadStream
|
|
4 |
instanceVariableNames:'collectBlock inStream'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Streams'
|
|
8 |
!
|
|
9 |
|
|
10 |
!CollectingReadStream class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
A stream which provides the result of applying a collectBlock
|
|
15 |
to the elements of an underlying stream.
|
|
16 |
"
|
|
17 |
!
|
|
18 |
|
|
19 |
examples
|
|
20 |
"
|
|
21 |
[exBegin]
|
|
22 |
|s|
|
|
23 |
|
|
24 |
s := CollectingReadStream
|
|
25 |
on:#(1 2 3 4 5 6 7 8) readStream
|
|
26 |
collecting:[:each | each squared].
|
|
27 |
s upToEnd
|
|
28 |
[exEnd]
|
|
29 |
|
|
30 |
[exBegin]
|
|
31 |
|s|
|
|
32 |
|
|
33 |
s := (#(1 2 3 4 5 6 7 8) readStream
|
|
34 |
selecting:[:n | n odd])
|
|
35 |
collecting:[:n | n squared].
|
|
36 |
s upToEnd
|
|
37 |
[exEnd]
|
|
38 |
"
|
|
39 |
! !
|
|
40 |
|
|
41 |
!CollectingReadStream class methodsFor:'instance creation'!
|
|
42 |
|
|
43 |
on:aStream collecting:aBlock
|
|
44 |
^ self basicNew on:aStream collecting:aBlock
|
|
45 |
! !
|
|
46 |
|
|
47 |
!CollectingReadStream methodsFor:'instance creation'!
|
|
48 |
|
|
49 |
on:aStream collecting:aBlock
|
|
50 |
inStream := aStream.
|
|
51 |
collectBlock := aBlock.
|
|
52 |
! !
|
|
53 |
|
|
54 |
!CollectingReadStream methodsFor:'queries'!
|
|
55 |
|
|
56 |
atEnd
|
|
57 |
^ inStream atEnd
|
|
58 |
! !
|
|
59 |
|
|
60 |
!CollectingReadStream methodsFor:'reading'!
|
|
61 |
|
|
62 |
next
|
|
63 |
inStream atEnd ifTrue:[
|
|
64 |
^ self pastEndRead
|
|
65 |
].
|
|
66 |
^ collectBlock value:(inStream next)
|
|
67 |
! !
|
|
68 |
|
|
69 |
!CollectingReadStream class methodsFor:'documentation'!
|
|
70 |
|
|
71 |
version_CVS
|
|
72 |
^ '$Header: /cvs/stx/stx/libbasic2/CollectingReadStream.st,v 1.1 2009-12-05 11:15:59 cg Exp $'
|
|
73 |
! !
|