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

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]
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

Слідкуй за CodeGalaxy

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

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