Take a look at the implementation of the following function, select the correct result:
def someFunction[A](list: List[A]): List[A] =
  list match {
    case Nil => sys.error("empty list")
    case Cons(_, t) => t
  }

someFunction(List(1))
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]
Explanation
List(1) can be represented as Cons(1, Nil). List(1) doesn’t match Nil. When matching against Cons(_, t) the following values are substituted: _ => 1, t => Nil. The latter is returned as a result. The someFunction implements function which returns tail of the list

Source: Scala Exercises: functional data structures

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Scala quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes