[squeak-dev] Smalltalk string API
eliot.miranda at gmail.com
Tue Feb 22 17:24:09 UTC 2011
On Mon, Feb 21, 2011 at 9:37 PM, Levente Uzonyi <leves at elte.hu> wrote:
> On Mon, 21 Feb 2011, Eliot Miranda wrote:
> Actually, thinking a little, why not
>> Collection >> join: delimiter
>> ^self species streamContents: [ :stream |
>> do: [ :each | each putOn: stream ]
>> separatedBy: [ delimiter putOn: stream ] ]
> Because I'd like this:
> #('foo' 'bar' 'baz') join: $-
> to return this:
> rather than this:
> #($f $o $o $- $b $a $r $- $b $a $z).
So then why not
SequenceableCollection >> join: delimiter
ifTrue: [ self ]
[ self first species streamContents:
[ :stream |
do: [ :each | each putOn: stream ]
separatedBy: [ delimiter putOn: stream ] ] ]
with first replaced by anyOne in Collection?
> Pharo's implementation dispatches on the class of the delimiter. That's
> fine, but requires multiple methods. Also I've never used #join: to create
> anything else but Strings.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev