On Thu, Jun 6, 2013 at 7:22 PM, Bill Myers <bill_my...@outlook.com> wrote:

> Scala has a similar design, with the following traits:
> - TraversableOnce: can be internally iterated once (has a foreach() method
> that takes a closure)
> - Traversable: can be internally iterated unlimited times (has a foreach()
> method that takes a closure)
> - Iterable: can be externally iterated (has an iterator() method that
> returns an Iterator trait)
>
> The way it works is that Iterable extends Traversable, which extends
> TraversableOnce, and the for loop just uses TraversableOnce, and Iterable
> has a default implementation of the TraversableOnce foreach() function
> using the iterator() function.
>
> Also, the Iterator trait itself extends TraversableOnce, implementing
> foreach() by mutating itself.
>
> It might be a good idea to investigate copying this design.
>

I find Andrei Alexandrescu's argument about range-based iterators pretty
persuasive: http://www.informit.com/articles/article.aspx?p=1407357

Seb
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to