【发布时间】:2017-12-09 13:28:40
【问题描述】:
以下 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来自哪里?
【问题讨论】:
-
我想,我们中的一些人只是喜欢嵌套......如果是
Seq[Seq[Seq[Seq[Seq[Int]]]]呢?