1
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)
}
4

1 に答える 1

8

.map((occ._1, _))の略です.map(i => (occ._1, i))

0 と の間の各要素に対して、上記のようocc._2に を作成しTupleます。したがって、これは、最初の要素が固定され、2 番目の要素が 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))
于 2013-05-17T11:40:18.477 に答える