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, 2, 3))
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
This is possible implementation of tail function. List(1, 2, 3) can be represented as Cons(1, Cons(2, Cons(3, Nil))). It doesn’t match Nil. When matching against Cons(_, t) the following values are substituted: _ => 1, t => Cons(2, Cons(3, Nil)) which is the same as List(2, 3).

Source: Scala Exercises: functional data structures

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Scala
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести