On 11 Mar 2014, at 10:19, Clément Bera <[email protected]> wrote:
> Hello, > > [ Note: So in the default Pharo the method is named #sort: not #sortByProp: > or #sortBy: but it's a detail ] Yes, my mistake, I was misguided by #isSortedBy: Now #sortByProp: is my own example method that accepts a block and executes it for each sortable item and then the result is compared. I don’t like the idea to implement #value:value: for a symbol because it caries a bit of a logic inside it. Uko > > I like this idea because I also have always the problem. So I would like to > be able to do: > > projects sort: #creationDate > > The implementation would be, in a similar fashion to how Symbol>>value: is > implemented for aCollection collect: #isPlague : > > Symbol>>value: val1 value: val2 > ^ (val1 perform: self) <= (val2 perform: self) > > Then : > > (#( 10 42 31 23 90 87 65) collect: #asValueHolder) sort: #value > > Answers: > > an Array(a NewValueHolder[ 10 ] a NewValueHolder[ 23 ] a NewValueHolder[ 31 > ] a NewValueHolder[ 42 ] a NewValueHolder[ 65 ] a NewValueHolder[ 87 ] a > NewValueHolder[ 90 ]) > > which is correct :-). > > However I do not like: > > projects sort: [ :proj | proj author birthDate ] > > If you allow that where is the limit to the thing you want to allow ? In > addition, I do not see any nice implementation and you could just implement > in project > > Project>>authorBirthDate > ^ self author birthDate > > Best, > > Clement > > > > 2014-03-11 9:19 GMT+01:00 Yuriy Tymchuk <[email protected]>: > Hi guys. > > This is a thing that I encounter quite often. > > Eg I have a collection of projects and I want to sort them by creation date. > It would be nice to be able to do something like: > > projects sortByProp: #creationDate > > or by birth date of the author > > projects sortByProp: [ :proj | proj author birthDate ] > > Maybe I’m wrong, but as I’ve told already I encounter it quite often and > writing something like > > projects sortBy: [ :prev :next | prev creationDate <= next creationDate ] > > is boring for me. > > Cheers. > Uko >
