RosettaCodeData/Task/Permutations/Scala/permutations-2.scala
2016-12-05 22:15:40 +01:00

11 lines
255 B
Scala

def permutations[T]: List[T] => Traversable[List[T]] = {
case Nil => List(Nil)
case xs => {
for {
(x, i) <- xs.zipWithIndex
ys <- permutations(xs.take(i) ++ xs.drop(1 + i))
} yield {
x :: ys
}
}
}