# Partial Functions January 28, 2013

Partial functions are functions that are not defined for all possible input.

The main distinction between PartialFunction and scala.Function1 is that the user of a PartialFunction may choose to do something different with input that is declared to be outside its domain.

So you can pretty much use a PartialFunction anywhere you would use a Function1 since it is a proper subtype, plus some extras.

The **applyOrElse** function used last in the above example takes a regular function and applies that if the partial function is not defined at the argument. There is one more method **orElse** that takes a partial function and creates a partial function that is defined at the union of the 2 partial functions that generate it. It is equivalent to a **case** statement that combines the functions. Note here that the order also matters in case the ranges overlap.