208. def patternMatching(x: Any) = x match {
}
case 1 | 2 | 3 = “one or two or three”
case d: Double = “double is here”
209. def patternMatching(x: Any) = x match {
}
case 1 | 2 | 3 = “one or two or three”
case d: Double = “double is here”
case s: String if s.size 5 = “short str”
210. def patternMatching(x: Any) = x match {
}
case 1 | 2 | 3 = “one or two or three”
case d: Double = “double is here”
case s: String if s.size 5 = “short str”
case _ = “anything else”
250. def sort(list: List[Int]): List[Int] =
list match {
case Nil = Nil
case head :: tail =
sort(tail.filter(_ head)) :::
head ::
sort(tail.filter(_ = head))
}
Functional code is hard to read at first.
251. def sort(list: List[Int]): List[Int] =
list match {
case Nil = Nil
case head :: tail =
sort(tail.filter(_ head)) :::
head ::
sort(tail.filter(_ = head))
}
Functional code is hard to read at first.