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

Cris Perdue cris at perdues.com
Sun Apr 2 21:57:27 EDT 2006


Bill Keese wrote:
> > I'm saying that that [iterating via callback function] is supported by
> > dojo.lang already, for native collections (i.e. arrays), and does not
> > need duplication within the Collections.
>
> Sorry Tom, I don't understand what one thing has to do with another.
>
>   Are you saying that people who like callback functions should avoid 
> using the Collection classes?  Or maybe you are saying that you can 
> call dojo.lang.forEach() on Collection objects?  (I don't think you can.)
>
> It seems to me that being able to call forEach(), every(), and some() 
> on Graphs etc. is a useful feature that will save other people writing 
> lines of code.
I agree that callback-style iteration is extremely useful.  The 
forEach(), every(), some() variety of callback iterators have succeeded 
in Lisps and Smalltalk in the early days, in Ruby and recent versions of 
Python from I believe 2.3. 

A recent email mentioned iteration over trees, and that is an especially 
attractive illustration of the good qualities of the callback style.  
With callbacks, the generator can be recursive, where with a "next" and 
"hasNext" style, the iterator object needs to contain a stack to 
maintain its place in a tree.  I'd like to see strong support in Dojo 
for the callback style.

Cheers,
Cris




More information about the dojo-contributors mailing list