GitBucket
Snippets
Sign in
marcus
/
FuncQS.scala
Fork
0
Created at Mon May 14 04:23:16 EDT 2018
Download ZIP
HTTP
Embed
Embed this snippet in your website.
HTTP
Clone with Git using the repository's web address.
Code
Revision
Forks
Marcus Bengtsson
revised this
on 14 May 2018
ddd0fe8
FuncQS.scala
// Functional quick-sort (not very effective) // Example of pattern matching, for comprehension and recursion def qs(list: List[Int]): List[Int] = list match { case Nil => Nil case x :: xs => lazy val ys = for (y <- xs if y <= x) yield y lazy val zs = for (z <- xs if z > x) yield z qs(ys) ++ List(x) ++ qs(zs) }