+ def combinations(occurrences: Occurrences): List[Occurrences] = {
+ def generator[T](x: List[List[T]]): List[List[T]] = x match {
+ case Nil => List(Nil)
+ case h :: t => for (j <- generator(t); i <- h) yield i :: j
+ }
+
+ def combinationsOnNumber(occurs : Occurrences) : List[Occurrences] =
+ generator(occurs map {case (c: Char, i: Int) => (1 to i) map (j => (c, j)) toList})
+
+ val combs = for (
+ i <- 1 to occurrences.length;
+ l <- occurrences combinations i;
+ l2 <- combinationsOnNumber(l)
+ ) yield l2
+
+ List() :: (combs toList)
+ }
+