for {
a <- Some(1)
b <- Some(2)
} yield (a, b)
戻りSome((1, 2))
Scalaのため、理解タプル分解を伴う
for {
a <- Right(1).right
b <- Left(2).left
} yield (a, b)
戻り
Left((1, 2))
は、今私は理解のためにタプルを分解します。
error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: scala.util.Either[Nothing,(Int, Int)]
(a, b) <- Right((1, 2)).right
error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: scala.util.Either[(Int, Int),Nothing]
なぜ、この最後の例では動作しません:
for {
(a, b) <- Some((1, 2))
(c, d) <- Some((3, 4))
} yield (a, b, c, d)
戻りSome((1, 2, 3, 4))
for {
(a, b) <- Right((1, 2)).right
(c, d) <- Left((3, 4)).left
} yield (a, b, c, d)
はコンパイルに失敗しますか?違いはなんですか?
を参照してください[バグ](https://issues.scala-lang.org/browse/SI-5589)は、この問題について報告があります。 – emilianogc