Scala either with a tuple as right

Suppose I have the following code:

val either: Either[String, (Int, Int)] = Right((1,2)) for { (a, b) <- either.right } yield a + b 

When I evaluate it in REPL, I get

: 13: error: constructor could not be created for the expected type; found: (T1, T2) required: scala.util.Either [Nothing, (Double, Double)] (a, b) <- a.right ^: 14: error: not found: value a} give a + b ^

Why do I have such an error? Can't I match the matching tuple with Either?

+6
source share
1 answer

The problem looks like a scala error https://issues.scala-lang.org/browse/SI-7222 . The conversion to understand flatMap / map format seems to have worked.

 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) 
+5
source

Source: https://habr.com/ru/post/970400/


All Articles