Pattern Matching in Scala
Pattern matching is a powerful feature in Scala that allows you to match values against patterns and execute different code depending on the match. Here's an example:
go
val day = "Monday"
day match {
case "Monday" => println("It's the first day of the week!")
case "Tuesday" => println("It's the second day of the week!")
case _ => println("It's not Monday or Tuesday.")
}
No comments:
Post a Comment