1
val list1 = List(1,2,3,4,5,6) //Creating a dummy List
val res1 = for(x <- list1 if x> 3) yield x
// returns res1: List[Int] = List(4, 5, 6)
val res2 = for(x <- list1) yield{
if (x>3) x //Filtering out values lesser then 3
}
//returns res2: List[AnyVal] = List((),(),(), 4, 5, 6)
//Expected this to be List(4, 5, 6)
上述產量如何根據「if」語句的位置返回不同的結果?斯卡拉產量發電機