> On 26.11.2014, at 17:18, Yuriy Tymchuk <[email protected]> wrote: > > Hi everyone! > > There is a Lint rule that suggests to use stream instead of strings > concatenation. What is the most common way, to create a string this way, > because the only thing I can come up with is: > > String streamContents: [ :stream | > stream > nextPutAll: 'Hello'; > nextPut: $ ; > nextPutAll: 'World’] > > But I’m not sure if it is the preferred solution.
Yes, that’s what I do. With one addition: The default size for such a stream is 100, so if I know that my collection is going to be significantly larger / smaller I initialize the collection directly: String new: 400 streamContents [: …. And for everyone who hasn’t yet discovered it: #streamContents is implemented on SequenceableCollection! That means you can do the same thing with arrays, orderedCollections etc. Streaming is awesome :) > > Cheers > Uko
