join

Ramon Leon ramonleon at cox.net
Fri Sep 15 03:44:49 UTC 2006


>> Sure we need it.  At Smallthought, we have a package of utility 
>> methods that includes:
>>
>> SequencableCollection>>joinTokens: aString
>>     ^ String streamContents:
>>         [:s |
>>         self do: [:ea | s nextPutAll: ea asString] separatedBy: [s 
>> nextPutAll: aString]]
>>
>> Looking through my sends to it, the argument is always either ' ' or 
>> ', ', so #joinedWithSpaces and #joinedWithCommas would probably be 
>> sensible methods to have too.
>>
>> Avi

Funny, one of the first extension methods I added when I learned 
Smalltalk, was join as well, I'm still amazed it isn't already there.  I 
got tired of typing out the stream version, and in all but one case, I 
was also joining on either ' ' or ', '.

Collection>>join: aString
     ^String streamContents: [:stream |
         self do: [:each | stream nextPutAll: each]
              separatedBy: [stream nextPutAll: aString]]

Avi, is there a reason you chose SequencableColleciton over just 
Collection, I'm curious if I've put mine in the wrong place, and the 
implications of doing so?




More information about the Squeak-dev mailing list