Matching Conditions

If you want to learn more, check out Scala Cookbook and Programming in Scala.

Create A String

// Create some strings
val text1 = "Man"
val text2 = "F"
val text3 = "Dog"

Create A Function That Uses A Match Expression

// Define a function that takes in a string, and matches it
def findGender(word: String) = word match {
    // If any of these words, return "Woman"
    case "Female" | "F" | "Woman" | "Lady" | "Girl" => "Woman"
    // If any of these words, return "Man"
    case "Male" | "M" | "Man" | "Gentleman" | "Boy" => "Man"
    // If anything else, return "Unknown"
    case _ => "Unknown"
}

Apply The Function To The Strings

findGender(text1)
Man
findGender(text2)
Woman
findGender(text3)
Unknown