Christoph Thiede uploaded a new version of Collections to project The Inbox: http://source.squeak.org/inbox/Collections-ct.1062.mcz
==================== Summary ====================
Name: Collections-ct.1062 Author: ct Time: 2 March 2024, 6:04:18.090276 pm UUID: 748d7c5e-d166-e44f-b72e-d444b71a1adc Ancestors: Collections-mt.1058
Proposal: Adds Collection>>orderedGroupBy:[having:] that maintains the order of the first occurence of each key.
Examples - to compare: ((1 to: 20) collect: #asWords) groupBy: #first. ((1 to: 20) collect: #asWords) orderedGroupBy: #first.
Also fixes typos in the comments of groupBy:[having:].
=============== Diff against Collections-mt.1058 ===============
Item was changed: ----- Method: Collection>>groupBy: (in category 'enumerating') ----- groupBy: keyBlock + "Like in SQL operation - Split the receivers contents into collections of elements for which keyBlock returns the same results, and return them." - "Like in SQL operation - Split the recievers contents into collections of elements for which keyBlock returns the same results, and return them."
| result | result := Dictionary new. self do: [ :each | | key | key := keyBlock value: each. (result at: key ifAbsentPut: [ OrderedCollection new ]) add: each ]. ^result!
Item was changed: ----- Method: Collection>>groupBy:having: (in category 'enumerating') ----- groupBy: keyBlock having: selectBlock + "Like in SQL operation - Split the receivers contents into collections of elements for which keyBlock returns the same results, and return those collections allowed by selectBlock." - "Like in SQL operation - Split the recievers contents into collections of elements for which keyBlock returns the same results, and return those collections allowed by selectBlock."
^(self groupBy: keyBlock) select: selectBlock!
Item was added: + ----- Method: Collection>>orderedGroupBy: (in category 'enumerating') ----- + orderedGroupBy: keyBlock + "Like in SQL operation - Split the receivers contents into collections of elements for which keyBlock returns the same results, and return them, maintaining the order of the first occurence of each key." + + | result | + result := OrderedDictionary new. + self do: [ :each | + | key | + key := keyBlock value: each. + (result at: key ifAbsentPut: [ OrderedCollection new ]) + add: each ]. + ^result!
Item was added: + ----- Method: Collection>>orderedGroupBy:having: (in category 'enumerating') ----- + orderedGroupBy: keyBlock having: selectBlock + "Like in SQL operation - Split the receivers contents into collections of elements for which keyBlock returns the same results, and return those collections allowed by selectBlock, maintaining the order of the first occurence of each key.." + + ^(self orderedGroupBy: keyBlock) select: selectBlock!
squeak-dev@lists.squeakfoundation.org