def drop[A](l: List[A], n: Int): List[A] =
if (n <= 0) l
else
l match {
case Nil => Nil
case Cons(_, t) => drop(t, n - 1)
}
drop(List(1, 2, 3), 0)
Assuming the following code is available for your reference
sealed trait List[+A]
case object Nil extends List[Nothing]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
Login in to like
Login in to comment