[Grace-core] Lists and filter

James Noble kjx at ecs.vuw.ac.nz
Sun Aug 3 11:01:53 PDT 2014


> 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