for {
a <- Some(1)
b <- Some(2)
} yield (a, b)
रिटर्न Some((1, 2))
स्काला के लिए-समझ टपल अपघटन के साथ
for {
a <- Right(1).right
b <- Left(2).left
} yield (a, b)
रिटर्न Left((1, 2))
अब मैं समझ के लिए में tuples विघटित करना चाहते हैं।
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