以下 Scala 代码编译良好:
val f = (input: String) => Some("result")
object Extract {
def unapply(input: String): Option[String] = f(input)
}
val Extract(result) = "a string"
但是,如果我将提取器替换为:
object Extract {
def unapply = f
}
然后编译失败:
error: an unapply result must have a member `def isEmpty: Boolean
val Extract(result) = "a string"
^
为什么?从哪里来def isEmpty: Boolean
?