作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有以下代码:
val either: Either[String, (Int, Int)] = Right((1,2))
for {
(a, b) <- either.right
} yield a + b
:13: error: constructor cannot be instantiated to expected type; found : (T1, T2) required: scala.util.Either[Nothing,(Double, Double)] (a, b) <- a.right ^ :14: error: not found: value a } yield a + b ^
最佳答案
问题似乎是 Scala 错误 https://issues.scala-lang.org/browse/SI-7222 .将 for comprehension 转换为 flatMap/map 符号似乎有效。
val either: Either[String, (Int, Int)] = Right((1, 2))
either.right.map {
case (a, b) =>
a + b
}
either: Either[String,(Int, Int)] = Right((1,2))
res0: Serializable with Product with scala.util.Either[String,Int] = Right(3)
关于Scala 的要么元组为 Right,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24066493/
我是一名优秀的程序员,十分优秀!