【发布时间】:2019-06-24 07:01:13
【问题描述】:
编译错误:
[error] found : ((Double, Double)) => scala.concurrent.Future[(Double, Double)]
[error] required: ((AnyVal, AnyVal)) => scala.concurrent.Future[?] [error](c: (Double, Double)) => Future(c).map(x=>x )
IDE 可以正常接受代码。
代码是使用 for 循环和 yield 编写的。我试图简化它。
def f(r: UUID, l: Int) = {
g(r).flatMap { (c: (Double, Double)) => /*** this part is just for the debugging ***/
Future(c).map(x=>x)
}
}
def g(r: UUID) = {
session.selectOne(
s"""
SELECT
${RR.x},
${RR.y}
FROM
${RR.g}
WHERE
${RR.r} = ?
ORDER BY
${RR.t} DESC
""",
r.toString
).map {
case Some(row) => (1.0,1.0) //will be replaced when it is working
case None => (0,0)
}
}
编译器发现 c 的类型是 (AnyVal, AnyVal) 我希望它是 (Double,Double)
【问题讨论】:
-
两个解决方案,第一个将 None case 更改为
(0.0d, 0.0d)。 secod (赌一个),在你的方法上使用显式类型签名。def g(r: UUID): (Double, Double).
标签: scala functional-programming future