[Newbies] How to doubble sort a collection

Tobias Pape Das.Linux at gmx.de
Wed Feb 4 18:33:01 UTC 2015

On 04.02.2015, at 19:22, Raymond Asselin <jgr.asselin at me.com> wrote:

> For now I implemented:
> sortedNotes
> ^notes sort:[:a :b | (a date = b date) and:[a temps > b temps]] .
> notesSorted
> ^notes sort:[:a :b | a date = b date 
> 		ifTrue:[a temps > b temps] 
>  		ifFalse:[a date > b date]] . 
> does exactly the same result.

sounds strange.
Probably you don't want to store date and time separated but as 
DateAndTime instances, then you just have to sort them by that.
Look at that class.
  Also, you can see that Date is a subclass of Timespan,
which implies a duration: a Date is a timespan of one day. You
probably don't want that if you compare them like above.

> But there is still notes in a same date that do not sort correctly, the begining is good and after 5 or so objects
> I get some witch do not seem to be sorted.

can you give an example?

> BTW don't know the difference between sort:  and sorted: 
> it seems as if the last one produce a new collection and the first one produce same collection but sorted.

#sorted: is like saying
	“Give me this, but sorted” and this “give me” typically results in a new collection.
#sort: is like saying
	“You! Sort yourself!” and implies mutation
	(a bit like set! in scheme or sort! in ruby)

> Note: I use 24 hours instead of a.m. / p.m. is this may cause problems?

see above


More information about the Beginners mailing list