Yes this is probably what I was also looking for. On Wed, Apr 19, 2017 at 11:07 PM, Peter Uhnak <[email protected]> wrote:
> We already have > > * #withIndexCollect: > * #withIndexDo: > > > So why not #withIndexSelect: ? > > #(#Object #subclass: #Point #instanceVariableNames:) withIndexSelect: [ > :each :i | i \\ 2 = 0 ] > > Peter > > p.s. for every second you could also do > aCollection pairsCollect: [ :first :second | second ] > > > On Wed, Apr 19, 2017 at 04:35:07PM -0300, Esteban A. Maringolo wrote: > > 2017-04-19 16:17 GMT-03:00 Stephane Ducasse <[email protected]>: > > > why? > > > Iterators are powerful and avoid that we all reinvent the wheel in our > own > > > corners. > > > > > > About keySelect: I do not see the point to convert a large collection > into a > > > dictionary then do yet another pass. > > > To me it looks like a hack. > > > > keySelect: would do a select based on the key (index in the case of > > SequenceableCollection) of the element, no need to create a > > Dictionary. > > > > keySelect: aBlock > > | result | > > result := self species new. > > self keysAndValuesDo: [:key :value | > > (aBlock value: key) ifTrue: [result add: value] > > ]. > > ^result > > > > > > You could implement #selectEverySecond or #selectEveryFirst in terms > > of the above. The name sounds weird though, but I'm not a native > > English speaker. > > > > Regarding #unzip it's a different story, I wouldn't use 'zip' in a > > selector for non Zip (compression) related methods. > > > > But do as you please, Pharo is yours as well ;) > > > > Regards! > > > > > > > I implemented > > > selectEvery: > > > (selectFirst selectSecond) as helpers. > > > > > > and also unzip all in one pass. > > > Now I have no problem to keep them for me but to me this is the wrong > > > attitude. > > > > > > Stef > > > > > > > > > testSelectEveryFirst > > > self assert: (#(#Object #subclass: #Point #instanceVariableNames: 'x y' > > > #classVariableNames: '' #package: 'Kernel-BasicObjects') > selectEveryFirst) > > > asArray equals: #(#Object #Point 'x y' '' 'Kernel-BasicObjects') > > > testSelectEverySecond self assert: (#(#Object #subclass: #Point > > > #instanceVariableNames: 'x y' #classVariableNames: '' #package: > > > 'Kernel-BasicObjects') selectEverySecond) asArray equals: #(#subclass: > > > #instanceVariableNames: #classVariableNames: #package:) > > > testUnzip > > > | uz | > > > uz := #(#Object #subclass: #Point #instanceVariableNames: 'x y' > > > #classVariableNames: '' #package: 'Kernel-BasicObjects') unzip. > > > self assert: uz first asArray equals: #(#Object #Point 'x y' '' > > > 'Kernel-BasicObjects'). > > > self assert: uz second asArray equals: #(#subclass: > #instanceVariableNames: > > > #classVariableNames: #package:) > > > > > > Esteban A. Maringolo > > > >
