Skip to content

Instantly share code, notes, and snippets.

@nilium
Forked from anonymous/gist:9263513
Created February 28, 2014 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilium/9263654 to your computer and use it in GitHub Desktop.
Save nilium/9263654 to your computer and use it in GitHub Desktop.
def max(list: List[Int]): Int = list match {
case Nil => throw new NoSuchElementException
case List(x) => x
case x +: tail =>
val rhs = max(tail)
if (x >= rhs) x else rhs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment