Skip to content

Instantly share code, notes, and snippets.

@petrbel
Created May 8, 2015 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petrbel/3e732f8c2118455fa884 to your computer and use it in GitHub Desktop.
Save petrbel/3e732f8c2118455fa884 to your computer and use it in GitHub Desktop.
Scala pattern matching in a nutshell
/* Scala pattern matching in a nutshell
======================================= */
/* Expectation
-------------- */
"param(value)" match {
case "param(" + val + ")" => println(s"OK! value == $val")
case _ => println("No way, bro")
}
/* Reality
---------- */
val Pattern = """param\((.*)\)"""
"param(value)" match {
case Pattern(val) => println(s"OK! value == $val")
case _ => println("No way, bro")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment