Created
May 8, 2015 15:01
-
-
Save petrbel/3e732f8c2118455fa884 to your computer and use it in GitHub Desktop.
Scala pattern matching in a nutshell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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