Ich bin neu für Scala. Ich habe eine Frage zu der Reihenfolge in der Foor-Schleife.Hat die Reihenfolge in Scala für Schleife Einfluss
type Occurrences = List[(Char, Int)]
lazy val dictionaryByOccurrences: Map[Occurrences, List[Word]] = dictionary.groupBy(x => wordOccurrences(x))
def wordAnagrams(word: Word): List[Word] = dictionaryByOccurrences.getOrElse(wordOccurrences(word), List())
def combinations(occurrences: Occurrences): List[Occurrences] = occurrences match {
case List() => List(List())
case head::tail => {
for (o <- combinations(tail); x <- 1 to head._2)
yield (head._1, x) :: o
}
wenn ich die Reihenfolge, in der for-Schleife ändern, wird es
def combinations(occurrences: Occurrences): List[Occurrences] = occurrences match {
case List() => List(List())
case head::tail => {
for (x <- 1 to head._2; o <- combinations(tail))
yield (head._1, x) :: o
}
falsch sein Ich kann nicht der Grund