I've forgotten why Traversable is more general than Iterable -- maybe it has to do with the parallel collections, and maybe they've said it was a mistake, or a toss-up.
But you can just:
scala> (Traversable(1,2,3), Traversable(3,4,5).toIterable).zipped.foreach( (a,b) => println(a,b) )
(1,3)
(2,4)
(3,5)
The supplementary question is whether there is a downside to introducing an implicit to do that for you.
Edit: to answer your question, I guess it would look like the following, but this is not a recommendation:
scala> implicit def `convert it`[A](t: Traversable[A]): Iterable[A] = t.toIterable
warning: there were 1 feature warning(s); re-run with -feature for details
convert$u0020it: [A](t: Traversable[A])Iterable[A]
scala> (Traversable(1,2,3), Traversable(3,4,5)).zipped.foreach( (a,b) => println(a,b) )
(1,3)
(2,4)
(3,5)
A "view" in this sense is a conversion function that lets you "view" the Traversable as an Iterable and does not necessarily have to do with a "collection view".
Update:
A peek at the source, and only the second collection must be iterable.
The reason is that Tuple2Zipped
will just foreach
-traverse the first collection, but iterate the second so that it can stop when !hasNext
.
There's interesting old discussion like:
http://www.scala-lang.org/old/node/2903.html
E.g., sample pull quote:
At least implicit in the contract of a Traversable is that you can
traverse it multiple times.
The best ryule for a public interface is to return a traversable when
you can. You can always turn it into am iterator if you need to.
And there is a question like this one that I think is mostly good for a laugh, though it is true enough.