I'm new for Scala. I have a question about the order in the foor loop.
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
}
if I change the order in the for loop, it will be wrong
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
}
I can not find the reason