Skip to content

Instantly share code, notes, and snippets.

@asmasa
Created June 6, 2014 04:08
Show Gist options
  • Save asmasa/54683263bf119f134535 to your computer and use it in GitHub Desktop.
Save asmasa/54683263bf119f134535 to your computer and use it in GitHub Desktop.
独書会 Scala IN DEPTH @ファミレス その1 ref: http://qiita.com/asmasa/items/f8f09655543cf171aaf3
x.foo(); /*is the same as*/ x foo
x.foo(y); /*is the same as*/ x foo y
x.::(y); /*is the same as*/ y :: x
def qsort[T <% Ordered[T]](list:List[T]):List[T] = {
list.match({
case Nil => Nil;
case x::xs =>
val (before,after) = xs.partition({ i => i.<(x) });
qsort(before).++(qsort(after).::(x)));
});
}
def qsort[T <% Ordered[T]](list:List[T]):List[T] = list match {
case Nil => Nil
case x :: xs =>
val (before, after) = xs partition ( _ < x )
qsort(before) ++ (x :: qsort(after));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment