我有一个
object radExtractor{
def unapplySeq(row:HtmlTableRow):Option[List[String]]={
val lista = (for{
a<-row.getByXPath("td/span/a")
ah= a.asInstanceOf[DomNode]
if(ah.getFirstChild!=null)
} yield a.asInstanceOf[DomNode].getFirstChild.toString).toList
lista match{
case Nil=>None
case l @ List(duns,companyname,address,city,postal,_bs,orgnummer, _*) =>Some(l)
case _ =>println("WTF");None
}
}
}
我想在列表理解中使用它,例如:
val toReturn = for{
rad<-rader
val radExtractor(duns,companyname,address,city,postal,_,orgnummer,_*)=rad
} yield Something(duns,companyname,address,city,postal,orgnummer)
但是当“rader”中的“rad”因为提取器返回而失败时,None
我得到一个MatchError
.
理解提取器不应该处理/忽略这些None
案例还是我只是错过了什么?
我可以做
val toReturn = rader.collect{case radExtractor(duns,companyname,address,city,postal,_,orgnummer, _*)=>
Something(companyname=companyname,address=address,city=city,postalcode=postal,orgnummer=orgnummer,duns=duns.toInt)
}
但这不会那么性感;)谢谢