[squeak-dev] Smalltalk string API
Eliot Miranda
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:
>
> snip
>
>
> Actually, thinking a little, why not
>>
>>
>> Collection >> join: delimiter
>>
>> ^self species streamContents: [ :stream |
>> self
>> do: [ :each | each putOn: stream ]
>> separatedBy: [ delimiter putOn: stream ] ]
>>
>> ?
>>
>
> Because I'd like this:
> #('foo' 'bar' 'baz') join: $-
> to return this:
> 'foo-bar-baz'
> rather than this:
> #($f $o $o $- $b $a $r $- $b $a $z).
>
So then why not
SequenceableCollection >> join: delimiter
^self isEmpty
ifTrue: [ self ]
ifFalse:
[ self first species streamContents:
[ :stream |
self
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.
>
>
> Levente
>
> snip
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20110222/27ede345/attachment.htm
More information about the Squeak-dev
mailing list
|