Search code examples
smalltalkpharo

How to get all items in from of Text from Ordered collection


simple question i got

|list string|
list:= #('ab' 'efghij' 'lmnopqrst'). "Ordered collection"
list do:[:each| "string with:each"  i know this is not right how do i add items ].

I tried streams too it returned me this "an ordered collection('ab' 'efghij' 'lmnopqrst')"

All i need is a single Text that has

'abc efghij lmnopqrst '

Solution

  • In Pharo you can do

    Character space join: list
    

    If join: is not available and it should perform well then you can use a stream variant

    String streamContents: [:stream| 
        list 
            do [:each| stream nextPutAll: each ]
            separatedBy: [ stream nextPut: Character space ]