基於我有限的知識,我知道編譯器會自動繼承集合返回類型,並基於它確定要返回的集合類型,因此在下面的代碼中,我想返回Option[Vector[String]]
。如何使用yield語句返回不同的集合
我試着用下面的代碼進行試驗和我得到的編譯錯誤
type mismatch; found : scala.collection.immutable.Vector[String] required: Option[Vector[String]]
代碼:
def readDocument(v:Option[Vector[String]]) : Option[Vector[String]] =
{
for (a <- v;
b <- a)
yield
{
b
}
}
或'for(v < - Some(Vector(「abc」)))yield v' – sourcedelica 2013-03-20 14:11:28