Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
pattern matching
:
Content language: English
Русский
What is the result of code execution? 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) 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]
pattern matching
What is the result of code execution? def dropWhile[A](l: List[A], f: A => Boolean): List[A] = l match { case Cons(h, t) if f(h) => dropWhile(t, f) case _ => l } dropWhile(List(1, 2, 3), (x: Int) => x < 2) 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]
pattern matching
What is the result of code execution? def dropWhile[A](l: List[A], f: A => Boolean): List[A] = l match { case Cons(h, t) if f(h) => dropWhile(t, f) case _ => l } dropWhile(List(1, 2, 3), (x: Int) => x > 2) 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]
pattern matching
What is the result of code execution? def dropWhile[A](l: List[A], f: A => Boolean): List[A] = l match { case Cons(h, t) if f(h) => dropWhile(t, f) case _ => l } dropWhile(List(1, 2, 3), (x: Int) => x > 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]
pattern matching
What is the result of code execution? def dropWhile[A](l: List[A], f: A => Boolean): List[A] = l match { case Cons(h, t) if f(h) => dropWhile(t, f) case _ => l } dropWhile(Nil, (x: Int) => x > 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]
pattern matching
What is the result of code execution? def init[A](l: List[A]): List[A] = l match { case Nil => sys.error("init of empty list") case Cons(_, Nil) => Nil case Cons(h, t) => Cons(h, init(t)) } init(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]
pattern matching
What is the result of code execution? def init[A](l: List[A]): List[A] = l match { case Nil => sys.error("init of empty list") case Cons(_, Nil) => Nil case Cons(h, t) => Cons(h, init(t)) } init(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]
pattern matching
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes