Created
March 6, 2010 21:20
-
-
Save retronym/323949 to your computer and use it in GitHub Desktop.
Inferring the return type of a partial function
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
| class PF[A] { | |
| def apply[B](pf: PartialFunction[A, B]) = pf | |
| } | |
| def pf[A] = new PF[A] | |
| pf[Any] { case 5 => true } | |
| def applyPf[A, B](a: A)(pf: PartialFunction[A, B]): Option[B] = | |
| if (pf.isDefinedAt(a)) Some(pf(a)) else None | |
| applyPf(1) { case 5 => true } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment