Pattern matching by tuple values within the "for-inclusion" range?
Given:
scala> val x: Either[Boolean, (Int, Int)] = Right( (5, 10) )
x: Either[Boolean,(Int, Int)] = Right((5,10))
I would like to match the pattern by the first and second values of the tuple in x.right, but this did not work:
scala> for {
| (a, b) <- x.right
| } yield a
<console>:14: error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: scala.util.Either[Nothing,(Int, Int)]
(a, b) <- x.right
^
I can do something like:
scala> for { a <- x.right } yield a match { case (x, y) => x }
res5: scala.util.Either[Boolean,Int] = Right(5)
But, is there a way to change my first non-compiled code to work?