scala-collection-compat
scala-collection-compat copied to clipboard
IterableOnce.iterator not available in Scala 2.12.x
Scala 2.12:
val t: TraversableOnce[Int] = List(1,2,3)
val tm = t.map(_ + 1)
migrating the above contrived example to Scala 2.13 (according to the @deprecated instructions) leads to:
Scala 2.13:
import scala.collection.compat.IterableOnce
val t: IterableOnce[Int] = List(1,2,3)
val tm = t.iterator.map(_ + 1) // since t.map was deprecated, requiring t.iterator.map
Trying to cross-compile the Scala 2.13 version to 2.12 using scala-collection-compat, we get a compilation error complaining about .iterator not being a member of TraversableOnce[Int]. Indeed, .iterator is only available on IterableOnce, but not in TraversableOnce. However, TraversableOnce does have a .toIterator method (but it's deprecated in IterableOnce).
Adding a .iterator extension method to TraversableOnce in scala-collection-compat for Scala 2.12- that calls .toIterator would solve the problem.