Is it intuitive to anyone that these two lines are not equivalent, and not in a small way? Does it seem desirable that this be the case?
for (X <- xs) yield X
xs map { case X => X }
Here we go:
scala> object X
defined module X
scala> val xs = List[Any](1)
xs: List[Any] = List(1)
scala> for (X <- xs) yield X
res1: List[Any] = List(1)
scala> xs map { case X => X }
scala.MatchError: 1 (of class java.lang.Integer)
at $anonfun$1.apply(<console>:10)
at $anonfun$1.apply(<console>:10)
But do it this way, and they behave the same!
scala> object X
defined module X
scala> val xs = List[Any]((1, 2))
xs: List[Any] = List((1,2))
scala> for ((X, X) <- xs) yield (X, X)
scala.MatchError: (1,2) (of class scala.Tuple2$mcII$sp)
at $anonfun$1.apply(<console>:10)
at $anonfun$1.apply(<console>:10)
scala> xs foreach { case (X, X) => (X, X) }
scala.MatchError: (1,2) (of class scala.Tuple2$mcII$sp)
at $anonfun$1.apply(<console>:10)
at $anonfun$1.apply(<console>:10)