姬長信(Redy)

Scala`view`:`force`不是`Seq`的成员


似乎应用地图和过滤器以某种方式将视图转换为Seq. documentation包含这个例子:

> (v.view map (_ + 1) map (_ * 2)).force
res12: Seq[Int] = Vector(4, 6, 8, 10, 12, 14, 16, 18, 20, 22)  

但如果我做类似的事情,我会收到一个错误:

> val a = Array(1,2,3)
> s.view.map(_ + 1).map(_ + 1).force
:67: error: value force is not a member of Seq[Int]

似乎如果我不止一次映射数组视图,SeqView就变成了Seq.

> a.view.map(_+1)
res212: scala.collection.SeqView[Int,Array[Int]] = SeqViewM(...)
> a.view.map(_+1).map(_+1)
res211: Seq[Int] = SeqViewMM(...)

我怀疑这种行为可能与Array是一个可变集合有关,因为我不能用List或Vector复制这种行为.但是,我可以根据需要多次过滤数组视图.