e.g. someObject mongoDo: [ ... ].

withIndexDo: obeys the principle of least astonishment to me.

Except the difference between this case and the other examples is that "withIndex + Do:" reverses the argument order (:e :i).

But more importantly, GNU and other Smalltalks have #doWithIndex:. I don���t think that the payoff here is enough to diverge from the rest of the world.

Lastly, apparently e.g. Dolphin has removed it completely in favor of #keysAndValuesDo: in response to a change in the ANSI standard. From http://forum.world.st/doWithIndex-tp3374968p3374975.html :
#doWithIndex: was in an early ANSI draft, presumably 
proposed by one of IBM's representatives but I can't really remember, and we 
had it in the version of Dolphin current at the time. Later it was removed 
from the standard and replaced with #keysAndValuesDo:, which makes sense 
since a sequenced collection can legimitately represent a "keyed collection" 
with integer keys. Therefore there is no need for a second enumerator that 
does the same thing but with key and value reversed.

Cheers,
Sean


View this message in context: Re: when iterating over a collection how to determine the current objects index
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.