【发布时间】:2019-09-27 02:23:07
【问题描述】:
f(Int) 是一个返回 Option[Int] 的函数。
def findIntPair(x: Int, y: Int): (Int, Int) = {
(f(x), f(y)) match {
case (None, None) || (None, _) || (_, None) => fail("Unable to find the pair" )
case (a, b) => (a.get, b.get) // why I still need to unwrap by get
}
}
为什么最后一个 case(a, b) 没有将它们解包到 Int 中,但仍将它们保留为 Option[Int]?
仅供参考:我正在使用 intelliJ IDEA。
【问题讨论】:
-
f的定义在哪里? -
你能详细说明一下函数 f()
标签: scala tuples pattern-matching