Peter Smet wrote:
I notice that collection with:do: is ok if the first collection is smaller than the second collection, but fails if the first collection is the larger. Since the method is happy to run with unequal sizes one way, for the sake of consistency, it should do so the other way also.
Here is a fix:
with: otherCollection do: twoArgBlock "Evaluate twoArgBlock with corresponding elements from this collection and otherCollection." 1 to: (self size min: otherCollection size) do: [:index | twoArgBlock value: (self at: index) value: (otherCollection at: index)]
IMO, if the two sizes do not match, an error should be raised. I'm doubting that anyone is actually reliably relying on leveraging this (mis)feature.
with: aCollection do: aBlock | rs | aCollection size = self size ifFalse: [self error: 'Collection sizes do not match']. rs := ReadStream on: aCollection. self do: [:each | aBlock value: each value: rs next]
and reimplemented in SequenceableCollection as
with: aCollection do: aBlock | index | aCollection size = self size ifFalse: [self error: 'Collection sizes do not match']. index := 0. aCollection do: [:each | aBlock value: (self at: (index := index + 1)) value: each]
-- Travis Griggs (a.k.a. Lord of the Fries) Member, Fraven Skreiggs Software Collective Key Technology P-P-P-Penguin Power!
squeak-dev@lists.squeakfoundation.org