Fwd: [dojo-contributors] [feedback wanted] Preferred Iteration forms

Tom Trenka ttrenka at gmail.com
Mon Apr 3 14:52:44 EDT 2006

Right now the collections code has no dependencies whatsoever, and I'd
prefer to keep it that way.  I also feel that writing a function to
encompass something that's accomplished in two lines in other code is kind
of a waste of time.

I'm also not talking about adding new, untested functions; I'm asking
because the iterator code in the Collections has been somewhat borken for a
while, and I need to fix it (two or three bugs filed against it).  The
imperative Iterator code has been there from the beginning, and the reason
why it got borken in the first place is because I wrote it following one
style, and someone tried to correct it to follow another.


On 4/3/06, Sandro Magi <smagi at naasking.homeip.net> wrote:
> Tom Trenka wrote:
> >Sorry, emailed it just to Alex first.
> >
> >---------- Forwarded message ----------
> >From: Tom Trenka <ttrenka at gmail.com>
> >Date: Apr 3, 2006 10:21 AM
> >Subject: Re: [dojo-contributors] [feedback wanted] Preferred Iteration
> forms
> >To: alex at dojotoolkit.org
> >
> >Alex,
> >
> >On any of the Array based Collections, you can *always* call toArray and
> use
> >the dojo.lang array functions to do functional iteration.  In theory you
> can
> >do the same with map-based collections by grabbing the KeyList from it
> and
> >using dojo.lang.forEach for it.
> >
> >Why would I want to duplicate that functionality if you've already
> written
> >it?
> >
> >
> If this is the approach you're taking, then why add yet more iteration
> functionality if it's already there? Isn't that just needlessly
> expanding the codebase?
> Instead of adding new, untested functions, you can trivially support
> functional iteration by using toArray and forEach yourself within the
> collections. Seems like a two-liner which is trivially testable, and
> gets you all the way there in terms of iteration functionality:
> function forEach(coll, unary_func) {
>   dojo.lang.forEach(coll.toArray(), unary_func, true);
> }
> Extra bonus: since you've copied the elements (or keys) to an array, you
> can mutate the collection while iterating over it.
> Sandro
> _______________________________________________
> 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/20060403/88473df0/attachment.htm 

More information about the dojo-contributors mailing list