Created
May 2, 2016 21:27
-
-
Save ryanpbrewster/c05e6619020578e5b1031ee445f592a1 to your computer and use it in GitHub Desktop.
Seq matching for Pattern matching in Scala 2.10 by Greg Methvin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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