Skip to content

Instantly share code, notes, and snippets.

@gaplo917
Last active January 15, 2017 16:57
Show Gist options
  • Save gaplo917/16b5434a6f9f547e2f44ab02b9287e5b to your computer and use it in GitHub Desktop.
Save gaplo917/16b5434a6f9f547e2f44ab02b9287e5b to your computer and use it in GitHub Desktop.
Scala Option Type Pattern matching
// Scala
// pattern matching in Option Type
val usernameOpt: Option[String] = Some("gary")
usernameOpt match {
case Some("gary") => println("matched gary!")
case Some("peter") => println("matched peter!")
case Some(username) => println("found ${username}, but no username is matched")
case None => println("No username is found")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment