Collection type generated by for with yield

Posted by Jesper on Stack Overflow See other posts from Stack Overflow or by Jesper
Published on 2010-06-01T07:18:24Z Indexed on 2010/06/01 7:23 UTC
Read the original article Hit count: 195

Filed under:
|
|

When I evaluate a for in Scala, I get an immutable IndexedSeq (a collection with array-like performance characteristics, such as efficient random access):

scala> val s = for (i <- 0 to 9) yield math.random + i
s: scala.collection.immutable.IndexedSeq[Double] = Vector(0.6127056766832756, 1.7137598183155291, ...

Does a for with a yield always return an IndexedSeq, or can it also return some other type of collection class (a LinearSeq, for example)? If it can also return something else, then what determines the return type, and how can I influence it?

I'm using Scala 2.8.0.RC3.

© Stack Overflow or respective owner

Related posts about scala

Related posts about collections