[squeak-dev] Generators on Streams on Generators on Collections
on ...
Bert Freudenberg
bert at freudenbergs.de
Tue Apr 12 16:35:01 UTC 2016
> On 12.04.2016, at 11:10, Tobias Pape <Das.Linux at gmx.de> wrote:
>
>
> On 12.04.2016, at 08:38, marcel.taeumel <Marcel.Taeumel at hpi.de> wrote:
>
>> Hi Tobias,
>>
>> this version is made for endless streams, not the ones the always operate on
>> a collection but sockets etc. So, the generator never ends and hence #atEnd
>> is never true. I thought that #upToNil might be sufficient and also
>> practical for other streams.
>>
>> Best,
>> Marcel
>
>
> Sounds reasonable :)
Actually, no, it does not ;)
If the stream hasn’t ended, the generator should continue. If the stream is at end, the generator should stop.
We don’t need #upToNil, you just need to stop the generator when the stream ends:
select: block
^ Generator on: [:g |
[self atEnd] whileFalse: [
| object |
object := self next.
(block value: object) ifTrue: [g yield: object]]]
... and similarly for the other methods. With that change, #upToEnd works just fine on the generator.
Agreed? :)
- Bert -
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4207 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20160412/a0ecfca8/smime.bin
More information about the Squeak-dev
mailing list
|