XML
val movies =
Pirates of the Caribbean
Edward Scissorhands
movies.text
val movieNodes = movies \ "movie"
movieNodes(0)
movieNodes(0) \ "@genre"
Pattern Matching
def fact(n: Int): Int =
if (n == 0) { 1 }
else { n * fact(n - 1) }
def fact(n: Int): Int = n match {
case 0 => 1
case n => n * fact(n - 1)
}
Pattern Matching
def fact(n: Int): Int = n match {
case 0 => 1
case n => n * fact(n - 1)
}
def factorial(n: Int): Int = n match {
case 0 => 1
case x if x > 0 => factorial(n - 1) * n
}
Pattern Matching
def toYesOrNo(choice: Int): String = choice match {
case 1 => "yes"
case 0 => "no"
case _ => "error"
}
def toYesOrNo(choice: Int): String = choice match {
case 1 | 2 | 3 => "yes"
case 0 => "no"
case _ => "error"
}
Pattern Matching
def f(x: Any): String = x match {
case i:Int => "integer: " + i
case _:Double => "a double"
case s:String => "I want to say " + s
}
Assignment
Keep working on the Assignment. Incorporate functional things