2014-06-05 5 views
6

मान लीजिए मैं कोड निम्नलिखित है:स्काला का या तो अधिकार के रूप में टपल साथ

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 ^

मैं ऐसे त्रुटि क्यों हैं मिल सकता है? क्या मैं किसी भी अधिकार से टुपल पर पैटर्न मिलान नहीं कर सकता?

उत्तर

5

समस्या एक स्कैला बग https://issues.scala-lang.org/browse/SI-7222 प्रतीत होता है। FlatMap/मानचित्र नोटेशन के लिए समझ के लिए कनवर्ट करना काम करता प्रतीत होता है।

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) 
+0

मैं स्कैला 2.10.3 का उपयोग कर रहा हूं। इसके अलावा इस तरह का एक अजीब प्रकार क्यों है: 'scala.util के साथ उत्पाद के साथ Serializable। या तो [स्ट्रिंग, Int] '? क्यों न सिर्फ 'scala.util.Either [स्ट्रिंग, Int] ' – maks

संबंधित मुद्दे