Skip to content

Instantly share code, notes, and snippets.

@girdharshubham
Last active March 21, 2019 18:56
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 girdharshubham/4955530df051f6183cb9b25ae20ac589 to your computer and use it in GitHub Desktop.
Save girdharshubham/4955530df051f6183cb9b25ae20ac589 to your computer and use it in GitHub Desktop.
val deepThoughtProcessor: PartialFunction[Int, Int] = {
case number:Int if number == 21 => number*2
}
deepThoughtProcessor isDefinedAt 22 // res0 = false
deepThoughtProcessor(21) // res1 = 42
/* Now, if you still try to invoke deepThoughtProcessor with the argument
* it's not defined at you'd get a MatchError
**/
deepThoughtProcessor(22) //MatchError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment