On 26.11.2014, at 17:18, Yuriy Tymchuk <yuriy.tymchuk@me.com> 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