aSortedCollection collect: returns OrderedCollection instead of original sorted

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

aSortedCollection collect: returns OrderedCollection instead of original sorted

Denis Kudriashov
Hi.

I just found that 

#() asSortedCollection select: [  ] => SortedCollection
#() asSortedCollection collect: [  ] => OrderedCollection

It feels like a bug to me. But maybe there is a reason why sorted collection collects items as OrderedCollection instead of original kind of sort? 

My usercase was copy of object with sorted collection inside. For this I just manually collect copy of each item. But at the end my copy became broken because of sort was important for domain logic. 

Best regards,
Denis
Reply | Threaded
Open this post in threaded view
|

Re: aSortedCollection collect: returns OrderedCollection instead of original sorted

Uko2
I think that this stick has 2 ends :). Often people have a collection and do not care how it ended up in that order, but want to preserve the order. Imagine that you have a collection of ascending numbers and you collect #negated and want to have the same order, but if you create a sorted collection, then it will reverse all the elements.

Uko

On 19 Jun 2017, at 11:04, Denis Kudriashov <[hidden email]> wrote:

Hi.

I just found that 

#() asSortedCollection select: [  ] => SortedCollection
#() asSortedCollection collect: [  ] => OrderedCollection

It feels like a bug to me. But maybe there is a reason why sorted collection collects items as OrderedCollection instead of original kind of sort? 

My usercase was copy of object with sorted collection inside. For this I just manually collect copy of each item. But at the end my copy became broken because of sort was important for domain logic. 

Best regards,
Denis

Reply | Threaded
Open this post in threaded view
|

Re: aSortedCollection collect: returns OrderedCollection instead of original sorted

Denis Kudriashov

2017-06-19 11:19 GMT+02:00 Yuriy Tymchuk <[hidden email]>:
I think that this stick has 2 ends :). Often people have a collection and do not care how it ended up in that order, but want to preserve the order. Imagine that you have a collection of ascending numbers and you collect #negated and want to have the same order, but if you create a sorted collection, then it will reverse all the elements.

Good point. I agree it is more important than my case
Reply | Threaded
Open this post in threaded view
|

Re: aSortedCollection collect: returns OrderedCollection instead of original sorted

gcotelli
In reply to this post by Denis Kudriashov
You can do anything in the collect block, so the returned objects possibly cannot be sorted, and even if it can be sorted maybe the sort block is not compatible.

On Mon, Jun 19, 2017 at 6:04 AM, Denis Kudriashov <[hidden email]> wrote:
Hi.

I just found that 

#() asSortedCollection select: [  ] => SortedCollection
#() asSortedCollection collect: [  ] => OrderedCollection

It feels like a bug to me. But maybe there is a reason why sorted collection collects items as OrderedCollection instead of original kind of sort? 

My usercase was copy of object with sorted collection inside. For this I just manually collect copy of each item. But at the end my copy became broken because of sort was important for domain logic. 

Best regards,
Denis

Reply | Threaded
Open this post in threaded view
|

Re: aSortedCollection collect: returns OrderedCollection instead of original sorted

philippeback
+100

On Mon, Jun 19, 2017 at 2:14 PM, Gabriel Cotelli <[hidden email]> wrote:
You can do anything in the collect block, so the returned objects possibly cannot be sorted, and even if it can be sorted maybe the sort block is not compatible.

On Mon, Jun 19, 2017 at 6:04 AM, Denis Kudriashov <[hidden email]> wrote:
Hi.

I just found that 

#() asSortedCollection select: [  ] => SortedCollection
#() asSortedCollection collect: [  ] => OrderedCollection

It feels like a bug to me. But maybe there is a reason why sorted collection collects items as OrderedCollection instead of original kind of sort? 

My usercase was copy of object with sorted collection inside. For this I just manually collect copy of each item. But at the end my copy became broken because of sort was important for domain logic. 

Best regards,
Denis