def combinations(occurrences: Occurrences): List[Occurrences] = occurrences match {
case List() => List(List())
case occ :: occs =>
for {
**occSub <- (0 to occ._2).map((occ._1, _)).toList**
occsCombination <- combinations(occs)
} yield (occSub :: occsCombination).filter(x => x._2 != 0)
}
答案 0 :(得分:8)
.map((occ._1, _))
是.map(i => (occ._1, i))
的缩写。
对于0和occ._2
之间的每个元素,它会像上面一样创建Tuple
。所以这会返回一个元组列表,第一个元素是固定的,第二个元素从0到occ._2
。
例如:
scala> val occ = (42,5)
occ: (Int, Int) = (42,5)
scala> (0 to occ._2).map(i => (occ._1, i)).toList
res0: List[(Int, Int)] = List((42,0), (42,1), (42,2), (42,3), (42,4), (42,5))
scala> (0 to occ._2).map((occ._1, _)).toList
res1: List[(Int, Int)] = List((42,0), (42,1), (42,2), (42,3), (42,4), (42,5))