[Newbies] sorting by key1 inside of key2

Joseph Alotta joseph.alotta at gmail.com
Thu Jul 7 02:58:30 UTC 2016


I have a collection of Transaction objects.  They have instance variables of category and payee.

A category might be “Office Expense”  and a payee might be “Costco” or “Amazon”.

I want to sort by categories and then payees.

Office Expense, Amazon…..
Office Expense, Costco

Here is some of my code:

sorted := trans asSortedCollection:  [:a :b | (a category) < (b category)].

sorted do:  [ :tr |  | cat pay |
	      cat := tr category.
	      pay := tr payee.
	      stream nextPutAll: (tr myPrintFormat2).

How do I make the sort block sort on both keys?



More information about the Beginners mailing list