一些Scala代码:
val list = List(Some("aaa"), Some("bbb"), None, ...)
list.filter(_!=None).map {
case Some(x) => x + "!!!"
// I don't want to handle `None` case since they are not possible
// case None
}
当我运行它时,编译器提示:
<console>:9: warning: match may not be exhaustive.
It would fail on the following input: None
list.filter(_!=None).map {
^
res0: List[String] = List(aaa!!!, bbb!!!)
如何在不提供
case None
的情况下修复该警告线?
最佳答案
如果您正在使用 map
之后 filter
,您可以使用 collect
.
list collect { case Some(x) => x + "!!!" }
关于list - 如何修复模式匹配详尽警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24751748/