---------- Forwarded message ----------
From: Nicolai Hess <nicolaih...@web.de>
Date: 2015-03-16 13:40 GMT+01:00
Subject: Re: [Pharo-users] when iterating over a collection how to
determine the current objects index
To: "jtuc...@objektfabrik.de" <jtuc...@objektfabrik.de>



2015-03-16 12:19 GMT+01:00 jtuc...@objektfabrik.de <jtuc...@objektfabrik.de>
:

>  Nicolai,
>
>
>
>
>
> Am 16.03.15 um 11:59 schrieb Nicolai Hess:
>
>
> 2015-03-14 11:55 GMT+01:00 Sean P. DeNigris <s...@clipperadams.com>:
>
>> Marcus Denker-4 wrote
>> > which version do we pick? We should pick one, rename the callers
>>
>> As someone mentioned earlier in the thread, #doWithIndex: has the
>> advantage
>> of mirroring the argument order (although this still should be
>> documented),
>> and it's the one most people are probably most familiar with, so IMHO it
>> makes sense to standardize on that.
>>
>
>  I like withIndexDo: because code like
>
>    so how would you name the current #do: if you had the choice?
>
> I still think this looks very logical:
>
> #do:
> #do:separatedBy:
> #doWithIndex:
> #doWithSomeOtherSpecialty:andEvenMoreStuff:
>
> And then there still ist the question if the order of the arguments should
> be changed:
>
> today:
>
> do: [:each| ]
> doWithIndex: [:each :index| ]
>
> future:
>
> do: [:each| ]
> withIndexDo: [:idx :each | ]
>
> Do you really think that is better?
>
> I think that if we move the withIndex part to the beginning of the
> message, it overstates the importance of the fact that we also need the
> index inside the iteration block.
>
>
>
>   aCollection withIndexDo: aBlock
>  reads like
>  "a collection with index"  do
>
>    This would make sense if it was a Collection with an Index.
>

no, that is the point.
A collection with no index:
aCollection do:

A collection with no index, but iterator over it like it had one:
aCollection withIndex  do:

>From the method comment:
withIndexDo: elementAndIndexBlock
    "Just like with:do: except that the iteration index supplies the second
argument to the block."

it looks like this method derives from :

SequenceableCollection>>#with: otherCollection do: twoArgBlock
    "Evaluate twoArgBlock with corresponding elements from this collection
and otherCollection."






> If there was an IndexedCollection class and maybe some message like
> asIndexedCollection or withIndex, which turns any collection into an
> IndexedCollection. Then the message might be a shortcut for "make thsi an
> indexed collection and iterate over it using its index" - comparable to
> Dictionary>>#keysAndValuesDo: - but please be aware that a Dictionary has
> keys and values by its very own nature. A Collection doesn't have an index
> (other than the fact that the elements are stored in some non-guarantueed
> order).
>
>
> This may all sound quite picky, but I think this is plain wrong and you
> are about to introduce not only incompatible, but also misleading naming
> for methods that exist on all Smalltalk dialects.
>


I don't want to rename it, it is already there. I just said I like the one
better than the other one.
But it is not really important, I am fine  with either or both. This was
just my explanation why I would choose withIndexDo:



>
> Joachim
>
>
>
>
>
>>
>>
>>
>> -----
>> Cheers,
>> Sean
>> --
>> View this message in context:
>> http://forum.world.st/when-iterating-over-a-collection-how-to-determine-the-current-objects-index-tp4810920p4811848.html
>>  Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>
>>
>
>
> --
> -----------------------------------------------------------------------
> Objektfabrik Joachim Tuchel          mailto:jtuc...@objektfabrik.de 
> <jtuc...@objektfabrik.de>
> Fliederweg 1                         http://www.objektfabrik.de
> D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
> Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
>
>
>

Reply via email to