Skip to content

Instantly share code, notes, and snippets.

@kastoestoramadus
Last active August 29, 2015 14:02
Show Gist options
  • Save kastoestoramadus/b7045bcbf9f775613d49 to your computer and use it in GitHub Desktop.
Save kastoestoramadus/b7045bcbf9f775613d49 to your computer and use it in GitHub Desktop.
package pl.japila.scalania.s99
object S99_P03 {
def nth[T](k: Int, ts: List[T]): Option[T] = {
if (k > 0) ts match {
case a :: tail => nth(k - 1, tail)
case Nil => None
}
else if (k == 0) Some(ts.head)
else None
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment