Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save retronym/323949 to your computer and use it in GitHub Desktop.

Select an option

Save retronym/323949 to your computer and use it in GitHub Desktop.
Inferring the return type of a partial function
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