Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ryanpbrewster/c05e6619020578e5b1031ee445f592a1 to your computer and use it in GitHub Desktop.
Save ryanpbrewster/c05e6619020578e5b1031ee445f592a1 to your computer and use it in GitHub Desktop.
Seq matching for Pattern matching in Scala 2.10 by Greg Methvin
def sort[T <% Ordered[T]](seq: Seq[T]): Seq[T] = seq match {
case Seq() => Seq()
case x +: xs =>
val (before, after) = xs partition (_ < x)
sort(before) ++ sort(x +: after)
}
sort(IndexedSeq("Greg", "Eishay", "Andrew"))
// => List(Andrew, Eishay, Greg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment