#sort: does it in place. I would use #sorted: (which does a copy) if you
want a behavior similar to #asSortedCollection:
I would convert the collection to an Array first, since only Array has
the sorting methods. also, why do you use #asString for the comparison?
Collection >> asSortedCollection
^self class new
addAll: self asArray sorted;
yourself
Collection >> asSortedCollection: aBlock
^self class new
addAll: (self asArray sorted: aBlock);
yourself
_but_ the selector #asSortedCollection would mean that the answered
object is an instance of SortedCollection, which is not present in Amber.
Cheers,
Nico
On 24/02/12 16:37, Tom wrote:
> Hi!
>
> I needed sorting and found
>
> Array sort: aSortBlock
>
> So I added asSortedCollection to the Collection class like...
>
> asSortedCollection
> ^self sort: [ :a :b | a asString< b asString ].
>
> It does a string compare on the collections contents and it works. Any
> complains about this aproach?
>
> Cheers...
--
Nicolas Petton
http://nicolas-petton.fr