6

Starting with a Scala list.

val list = List(1,2,3,4)

How can I convert it to a TraversableOnce?

merlin2011
  • 71,677
  • 44
  • 195
  • 329
Phil
  • 46,436
  • 33
  • 110
  • 175

2 Answers2

9

You already have one, since List[A] is a subtype of TraversableOnce[A]. You should not need to do anything to convert it.

To verify this:

scala> implicitly[List[Int] <:< TraversableOnce[Int]]
res0: <:<[List[Int],TraversableOnce[Int]] = <function1>
Ben James
  • 121,135
  • 26
  • 193
  • 155
0
list.iterator

would do the trick if you specifically need to iterate, but your list is already a TraversableOnce

http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.List

Guillaume
  • 22,694
  • 14
  • 56
  • 70