scala implicit or explicit conversion from iterator to iterable

Posted by landon9720 on Stack Overflow See other posts from Stack Overflow or by landon9720
Published on 2010-04-30T18:35:40Z Indexed on 2010/04/30 20:27 UTC
Read the original article Hit count: 183

Filed under:
|

Does Scala provide a built-in class, utility, syntax, or other mechanism for converting (by wrapping) an Iterator with an Iterable?

For example, I have an Iterator[Foo] and I need an Iterable[Foo], so currently I am:

 val foo1: Iterator[Foo] = ....
 val foo2: Iterable[Foo] = new Iterable[Foo] {
   def elements = foo1
 }

This seems ugly and unnecessary. What's a better way?

© Stack Overflow or respective owner

Related posts about scala

Related posts about collections