for {
a <- Some(1)
b <- Some(2)
} yield (a, b)
rendimenti Some((1, 2))
Scala per-la comprensione con decomposizione tuple
for {
a <- Right(1).right
b <- Left(2).left
} yield (a, b)
restituisce Left((1, 2))
Ora voglio decomporsi tuple in per la comprensione.
for {
(a, b) <- Some((1, 2))
(c, d) <- Some((3, 4))
} yield (a, b, c, d)
rendimenti Some((1, 2, 3, 4))
for {
(a, b) <- Right((1, 2)).right
(c, d) <- Left((3, 4)).left
} yield (a, b, c, d)
fallisce la compilazione:
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]
Perché non quest'ultimo esempio funziona? Qual è la differenza?
C'è un [Bug] (https://issues.scala-lang.org/browse/SI-5589) hanno riportato per questo problema. – emilianogc