def combs[A](n: Int, l: List[A]): Iterator[List[A]] = n match { case _ if n < 0 || l.lengthCompare(n) < 0 => Iterator.empty case 0 => Iterator(List.empty) case n => l.tails.flatMap({ case Nil => Nil case x :: xs => combs(n - 1, xs).map(x :: _) }) }