dict := {'a' -> 'first'. 'b' -> 'second'. 'c' ->'third'} as: Dictionary.
Yes, this printed #('second' 'third' 'first'), so now we need to sort. I have the idiom in my head but I typed in in anyway to verify
| dict |
dict := {'a' -> 'first'. 'b' -> 'second'. 'c' ->'third'} as: Dictionary.
dict keys asSortedCollection collect: [:key | dict at: key]
And this indeed gives an OrderedCollection('first' 'second' 'third')
So if I had sent an answer to your question I probably would have just pasted the line
dict keys asSortedCollection collect: [:key | dict at: key]
not even mentioning that it took me a minute to verify, and that en passant I discovered that dictionary printing is sorted for a couple of years already, which I had not noticed ;)
Comparing this to Randal's suggestion I'd say that mine feels more "Smalltalky". Accessing the associations in a dictionary directly feels unclean. Maybe because it breaks the abstraction, associations are an implementation detail of dictionaries. It's unlikely this will ever change and accessing the associations is fine, but still ;)
- Bert -