sorting by key1 inside of key2

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

sorting by key1 inside of key2

Joseph Alotta
Greetings,

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?

Sincerely,

Joe.





_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sorting by key1 inside of key2

Ben Coman
On Thu, Jul 7, 2016 at 10:58 AM, Joseph Alotta <[hidden email]> wrote:

> Greetings,
>
> 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)].

Just guessing...
    [:a :b | (a category) = (b category)
                    ifFalse: [ (a category) < (b category) ]
                    ifTrue: [ (a payee) < (b payee)]].

cheers -ben

>
> 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?
>
> Sincerely,
>
> Joe.
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sorting by key1 inside of key2

Joseph Alotta
thank you, ben!!


> On Jul 6, 2016, at 11:17 PM, Ben Coman [via Smalltalk] <[hidden email]> wrote:
>
> [:a :b | (a category) = (b category)
>                     ifFalse: [ (a category) < (b category) ]
>                     ifTrue: [ (a payee) < (b payee)]].

Loading...