On 25 Jun 2018, at 12:56, Herbert VojÄÃk <herby@mailbox.sk> wrote:
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 << '...' ]).
I like the first version with the (little known, but still standard and clear) #in: selector. I can't see how the second is 'better', as it looks equally 'complex' but adds a new selector, #pipe: All this, IMHO.
Herby
To separate the composition from the usage? Thanks, Peter