Since the generators for (Any, Any) <- Or are not "incontrovertible", filters are added to the desugared code ( why should a filter be defined to match patterns in a for loop in scala? ), Resulting in:
Right((1, 2)).right.filter { case (a, b) => true; case _ => false }.flatMap({ case(a, b) => Left((3, 4)).left.filter { case (c, d) => true; case _ => false }.map({case (c, d) => (a, b, c, d) }) })
There is a compilation error in the filters, because the filter method for Right looks like this (left looks like):
def filter[X](p: B => Boolean): Option[Either[X, B]] = e match { case Left(_) => None case Right(b) => if(p(b)) Some(Right(b)) else None }
This means that the compiler is trying to do the following:
(T1, T2) match { case Left(_) => None case Right(b) => if(p(b)) Some(Right(b)) else None }
Which fails because (T1, T2) cannot be entered in either [A, B] (which goes straight on), where A is Nothing and B is (Int, Int).
You can get something close to this using:
for { a <- Right((1, 2)).right b <- Left((3, 4)).left } yield (a, b) match { case ((c, d), (e, f)) => (c, d, e, f) case _ => }