Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.learner.s99
- object P03 {
- def nth(n: Int, l: List[Any]): Any = {
- require(n >= 0, "n must be greater than or equal to zero")
- l match {
- case List() => None
- case head :: tail if n == 0 => head
- case head :: tail if n > 0 => nth(n - 1, tail)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement