<br><br><div class="gmail_quote">On Tue, Feb 22, 2011 at 9:59 AM, Levente Uzonyi <span dir="ltr"><<a href="mailto:leves@elte.hu">leves@elte.hu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Tue, 22 Feb 2011, Eliot Miranda wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Feb 21, 2011 at 9:37 PM, Levente Uzonyi <<a href="mailto:leves@elte.hu" target="_blank">leves@elte.hu</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, 21 Feb 2011, Eliot Miranda wrote:<br>
<br>
snip<br>
<br>
<br>
Actually, thinking a little, why not<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
Collection >> join: delimiter<br>
<br>
^self species streamContents: [ :stream |<br>
self<br>
do: [ :each | each putOn: stream ]<br>
separatedBy: [ delimiter putOn: stream ] ]<br>
<br>
?<br>
<br>
</blockquote>
<br>
Because I'd like this:<br>
#('foo' 'bar' 'baz') join: $-<br>
to return this:<br>
'foo-bar-baz'<br>
rather than this:<br>
#($f $o $o $- $b $a $r $- $b $a $z).<br>
<br>
</blockquote>
<br>
So then why not<br>
<br>
SequenceableCollection >> join: delimiter<br>
<br>
^self isEmpty<br>
ifTrue: [ self ]<br>
ifFalse:<br>
[ self first species streamContents:<br>
[ :stream |<br>
self<br>
do: [ :each | each putOn: stream ]<br>
separatedBy: [ delimiter putOn: stream ] ] ]<br>
<br>
with first replaced by anyOne in Collection?<br>
</blockquote>
<br></div></div>
This assumes that the receiver is a collection of objects whose species is Array or a subclass of String (#streamContents: doesn't work with other collections IIRC). If that's the case, then there's no need to use #putOn:, because #nextPutAll: does the same and it's faster too.<br>
<br>
With my version, this:<br>
#(1 2 3) join: $- returns this:<br>
'1-2-3'.<br></blockquote><div><br></div><div>got it. finally. sorry :)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><font color="#888888">
<br>
<br>
Levente</font><div><div></div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Pharo's implementation dispatches on the class of the delimiter. That's<br>
fine, but requires multiple methods. Also I've never used #join: to create<br>
anything else but Strings.<br>
<br>
<br>
Levente<br>
<br>
snip<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br>