Type Mismatch on Scala For Comprehension
问题 Why does this construction cause a Type Mismatch error in Scala? for (first <- Some(1); second <- List(1,2,3)) yield (first,second) <console>:6: error: type mismatch; found : List[(Int, Int)] required: Option[?] for (first <- Some(1); second <- List(1,2,3)) yield (first,second) If I switch the Some with the List it compiles fine: for (first <- List(1,2,3); second <- Some(1)) yield (first,second) res41: List[(Int, Int)] = List((1,1), (2,1), (3,1)) This also works fine: for (first <- Some(1);