Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.632.mcz ==================== Summary ==================== Name: Collections-ul.632 Author: ul Time: 5 May 2015, 1:10:58.584 am UUID: 5581dccd-80b4-4a89-8918-450ff62093da Ancestors: Collections-mt.631 Removed MutexForPicking and RandomForPicking from Collection along with the methods referencing them, because the accessor methods were private, and they were only intended to be used for shuffling. Separated #groupBy: from #groupBy:having:. =============== Diff against Collections-mt.631 =============== Item was changed: Object subclass: #Collection instanceVariableNames: '' + classVariableNames: '' - classVariableNames: 'MutexForPicking RandomForPicking' poolDictionaries: '' category: 'Collections-Abstract'! !Collection commentStamp: '<historical>' prior: 0! I am the abstract superclass of all classes that represent a group of elements.! Item was changed: ----- Method: Collection class>>initialize (in category 'class initialization') ----- initialize "Set up a Random number generator to be used by atRandom when the user does not feel like creating his own Random generator." - RandomForPicking := Random new. - MutexForPicking := Semaphore forMutualExclusion. Smalltalk addToStartUpList: self! Item was removed: - ----- Method: Collection class>>mutexForPicking (in category 'private') ----- - mutexForPicking - ^ MutexForPicking! Item was removed: - ----- Method: Collection class>>randomForPicking (in category 'private') ----- - randomForPicking - - self deprecated: 'Use ThreadSafeRandom value instead. It''s not thread-safe to use this instance without the unaccessible MutexForPicking semaphore.'. - ^ RandomForPicking! Item was removed: - ----- Method: Collection class>>startUp (in category 'system startup') ----- - startUp - "Reseed the random generator at startup time such that a reloaded - project will not repeat a previous pseudo-random sequence when - selecting at random from a collection." - - MutexForPicking - critical: [RandomForPicking initialize]! Item was added: + ----- Method: Collection>>groupBy: (in category 'enumerating') ----- + groupBy: keyBlock + "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 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! - | result | - result := Dictionary new. - self do: - [ : each | | key | - key := keyBlock value: each. - (result - at: key - ifAbsentPut: [ OrderedCollection new ]) add: each ]. - ^ result select: selectBlock! |
Free forum by Nabble | Edit this page |