Skip to content

Instantly share code, notes, and snippets.

@maxaf
Created March 15, 2011 04:55
Show Gist options
  • Save maxaf/870332 to your computer and use it in GitHub Desktop.
Save maxaf/870332 to your computer and use it in GitHub Desktop.
scala> def isEven(i: Int): Boolean = { println("checking %d".format(i)); i % 2 == 0 }
isEven: (i: Int)Boolean
scala> val pf: PartialFunction[Int, Boolean] = { case i if isEven(i) => { println("%d is even".format(i)); true } }
pf: PartialFunction[Int,Boolean] = <function1>
scala> pf.isDefinedAt(0)
checking 0
res0: Boolean = true
scala> pf(0)
checking 0
0 is even
res1: Boolean = true
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment