Option を使用して値の定義を使用して for を作成すると、期待どおりに機能します。
scala> for (a <- Some(4); b <- Some(5); val p = a * b) yield p
res0: Option[Int] = Some(20)
値の定義がない場合、Either で同じことを行うと機能します。
scala> for (a <- Right(4).right; b <- Right(5).right) yield a * b
res1: Either[Nothing,Int] = Right(20)
しかし、値の定義を使用すると、scala は for 内包の間違ったコンテナー タイプを推測するようです。
scala> for (a <- Right(4).right; b <- Right(5).right; val p = a * b) yield p
<console>:8: error: value map is not a member of Product with Serializable with Either[Nothing,(Int, Int)]
for (a <- Right(4).right; b <- Right(5).right; val p = a * b) yield p
^
なぜこれを行うのですか?この動作を回避する方法は何ですか?