[dojo-contributors] [feedback wanted] Preferred Iterationforms

Tom Trenka ttrenka at gmail.com
Wed Apr 12 16:43:31 EDT 2006


Scott,
I had combined your next and current, and in all honesty I'd prefer to keep
it that way; it was the separation of the two that caused the headaches in
the first place (the originals used moveNext(), which returned the value of
atEnd, and apparently that caused some misunderstandings about how the
iterators worked which leads us to where we are today).

Under my suggestion here, current() would return you the current item *and*
advance the internal cursor.  I would provide an "item" property only if
someone, for some reason, needed to gain another reference to the current
item in the collection.  But I would expect the dev to be using current()
and atEnd().

trt

On 4/12/06, Scott J. Miles <sjmiles at turbophp.com> wrote:
>
> Seems like we went down this road already, but because I can't keep my
> mouth shut, I still say this is my personal preference:
>
> it.atEnd( ) -> boolean EOI indicator
> it.next( ) -> advance position, return value of it.atEnd()
> it.current( ) -> return current item
>
> Then you can be compact like so:
>
> while (it.next()) {
>   ...
> }
>
> Or if you prefer
>
>  while (!it.atEnd()) {
>  ...
>  it.next();
> }
>
> or any of various other constructions
>
> Regards,
> Scott J. Miles
> TurboAjax Group
> http://www.turboajax.com
>  ------------------------------
> *From:* dojo-contributors-bounces at dojotoolkit.org [mailto:
> dojo-contributors-bounces at dojotoolkit.org] *On Behalf Of *Tom Trenka
> *Sent:* Wednesday, April 12, 2006 12:36 PM
> *To:* dojo dev.
> *Subject:* Re: [dojo-contributors] [feedback wanted] Preferred
> Iterationforms
>
> item in that example does, in fact, represents current item and not the
> next item.  Brief example on the function (non functional, pseudo code)
>
> iterator.current=function(){
>    var ret=internal[currentPosition];
>    currentPosition++;
>   return ret;
> }
>
> so the return from that function should be the current item and not the
> next item, which is why I was calling it current().
>
> I'm fine with next, but that's the way it will end up working (i think).
>
> On 4/12/06, Jon Sykes <jon.sykes at media-hive.com> wrote:
> >
> > while(!it.atEnd()){
> >         var item=it.current();
> >         do stuff
> > }
> >
> > If var item in this example represents the current item not the next
> > I think calling it next will be mad crazy confusing.
> >
> > If it's not, and it is the next item, it makes sense.
> >
> >
> > Jon Sykes
> >
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.385 / Virus Database: 268.4.1/310 - Release Date: 4/12/2006
>
> _______________________________________________
> dojo-contributors mailing list
> dojo-contributors at dojotoolkit.org
> http://dojotoolkit.org/mailman/listinfo/dojo-contributors
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20060412/678033df/attachment.htm 


More information about the dojo-contributors mailing list