[BUG] collection with: do: on uneven sizes problem...
Travis Griggs
tgriggs at keyww.com
Fri May 28 16:09:55 UTC 1999
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!
More information about the Squeak-dev
mailing list
|