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?
Iteratorhas atoIterablemethod in Scala 2.8.0, but not in 2.7.7 or earlier. It’s not implicit, but you could define your own implicit conversion if you need one.