1
爲什麼此代碼的工作:混淆在斯卡拉在List.foldRight()參數
val list = List(('a', 2), ('b', 2))
val first = list.foldRight(List[List[(Char, Int)](List())) {
case ((char, num), acc) =>
(for (
elem <- acc;
i <- 0 to num
) yield (char, i) :: elem)
}
哪裏,因爲這不:
val second = list.foldRight(List[List[(Char, Int)]](List())) {
(elem, acc) =>
(for (
elem1 <- acc;
(char, num) <- elem; // ERROR: value filter is not a member of (Char, Int)
i <- 0 to num
) yield (char, i) :: elem1)
}
我不是在做的都一樣,只是在不同的地方?
啊,所以OP試圖用發電機'<-'語法上非集合(一個元組),這不是工作的正確工具 –