[Grace-core] Lists and filter

Kim Bruce kim at cs.pomona.edu
Sun Aug 3 11:15:06 PDT 2014


This is one of those issues where there is a different answer for professionals & novices. Professionals appreciate the generality of getting back an iterator that can be converted to a list if necessary. Novices learning lists have no idea what iterators are. 

Sent from my iPad

On Aug 3, 2014, at 11:01 AM, James Noble <kjx at ecs.vuw.ac.nz> wrote:

>> I'm a bit surprised that the method filter on a list returns an iterator.  I'm not planning on explaining iterators to my first course students (it's more appropriate for students in data structures).  That means I can't really teach my students about filter on lists.  Why not have filter on iterator return an iterator, but filter on lists return a list?
> 
> I guess this depends on how we want to design out collection library.
> what we have now probably won't be the final word on the matter! 
> 
> generally you'll want iterators (or really, streams)  so that e.g. things can be done lazily,
> without necessarily allocating a full collection at each stage in a chain.
> 
> Marco writes
>> why an iterator can not be a special kind of list?
> 
> because a list can do more than an iterator (in particular, more than a stream) 
> A stream may offer only one-time access to each element, 
> but a collection is obviously more flexible
> 
> James
> 
>> Kim
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Grace-core mailing list
>> Grace-core at cecs.pdx.edu
>> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core
> 



More information about the Grace-core mailing list