[Pharo-users] Pharo 7 streams API

Herbert Vojčík herby at mailbox.sk
Mon Jun 25 06:56:04 EDT 2018



Peter Uhnák wrote on 23. 6. 2018 15:39:
> Hi,
> 
> I'm starting to familiarize myself with new streams, and one thing I've 
> noticed is the removal of #lineEndConvention (which I use all the time).
> 
> So a statement like this
> 
> aFile writeStreamDo: [ :stream |
> stream lineEndConvention: #lf.
> stream << '...'> ].
> 
> has to be written like so
> 
> aFile writeStreamDo: [ :rawStream | |stream|
> stream := (ZnNewLineWriterStream on: rawStream) forLf.
> stream << '...'
> ].
> 
> which feels very messy because I am mixing writing with the 
> configuration. And I don't even take account for buffered/encoded 
> decorators. Plus it increases the incidental complexity -- I need 
> another variable, and I can accidentally write to the wrong stream, etc.
> 
> Would a method like #writeStream:do: (or #writeStreamTransform:do:) make 
> sense? E.g.
> 
> aFile writeStreamTransform: [ :stream | (ZnNewLineWriterStream on: 
> stream) ] do: [ :stream |
> stream << '...'
> ]

   aFile writeStreamDo: [ :rawStream |
     (ZnNewLineWriterStream on: rawStream) in: [ :stream |
       stream << '...' ] ].

As for transformation, I'd go for some more generic (functional?) 
approach like:

   aFile writeStreamDo: ([:x | ZnNewLineWriterStream on: x] pipe: [ 
:stream |
     stream << '...' ]).

Herby

> To separate the composition from the usage?
> 
> Thanks,
> Peter



More information about the Pharo-users mailing list