Skip to content

Instantly share code, notes, and snippets.

@girdharshubham
Last active March 21, 2019 18:08
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/dd445d34daba348fa8bcacd4d9047388 to your computer and use it in GitHub Desktop.
Save girdharshubham/dd445d34daba348fa8bcacd4d9047388 to your computer and use it in GitHub Desktop.
val deepThoughtProcessor = new PartialFunction[Int, Int] {
override def isDefinedAt(number: Int): Boolean = number == 21
override def apply(number: Int) = number * 2
}
val deepThoughQuery = deepThoughtProcessor isDefinedAt 22 // res0 = false
val lifeUniverseEverything = deepThoughtProcessor apply 21 //res1 = 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment