Lazy Quicksort in Scala
问题 Is it possible to do this sort of thing in Scala? 回答1: def quicksort[A](xs: Stream[A])(implicit o: Ordering[A]): Stream[A] = { import o._ if (xs.isEmpty) xs else { val (smaller, bigger) = xs.tail.partition(_ < xs.head) quicksort(smaller) #::: xs.head #:: quicksort(bigger) } } It can be done with views as well, though it's bound to be much slower: def quicksort[A](xs: List[A])(implicit o: Ordering[A]) = { import o._ def qs(xs: SeqView[A, List[A]]): SeqView[A, Seq[_]] = if (xs.isEmpty) xs else