join

J J azreal1977 at hotmail.com
Sat Sep 16 13:06:47 UTC 2006


Forgive my newbieness, but doesn't smalltalk already have a join called ","  
(e.g. #(1 2 3) , #(4 5 6) ----> #(1 2 3 4 5 6) )?


>From: Keith Hodges <keith_hodges at yahoo.co.uk>
>Reply-To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>Subject: join
>Date: Fri, 15 Sep 2006 00:57:52 +0100
>
>Entirely against my will, I once worked in a perl shop, and I noticed that 
>perlites liked joining things.
>
>Whenever I find myself wanting to join a bunch of items together (e.g. to 
>make a path) I am never satisfied with the result and so I took a look at 
>the Collections/String classes to see whether anything fitted nicely.
>
>
>I came up with
>
>SequencableCollection>>join: aCollection
>
>    ^ self class streamContents: [ :stream |
>        aCollection
>            do: [ :each | stream nextPut: each ]
>            separatedBy: [ stream nextPutAll: self ] ]
>
>
>and
>
>Character>>join: aCollectionOfStrings
>
>    ^ self class streamContents: [ :stream |
>        aCollectionOfStrings
>            do: [ :each | stream nextPutAll: each ]
>            separatedBy: [ stream nextPut: self ] ]
>
>and
>
>Collection>>joinWith: aCollection
>
>aCollection join: self
>
>----
>This now allows
>
>(Array with: 1 with: 2) join: (Array with: 3 with: 4 with: 5)
>$/ join: (Array with: 'Hello' with: 'my' with: 'World').
>
>any thoughts? I am curious as to why #join: hasn't made it into the core 
>image, and if it were to how would it happen?
>
>Keith
>
>
>___________________________________________________________ The all-new 
>Yahoo! Mail goes wherever you go - free your email address from your 
>Internet provider. http://uk.docs.yahoo.com/nowyoucan.html
>





More information about the Squeak-dev mailing list