下面的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]]]]? – Dima