A partial function is a function that is valid for only a subset of values of those types you might pass in to it.

Partial function can be defined by using ‘case’ statement.

Let us define a partial function and to know how to use it.

```
val multiplyBy100: PartialFunction[Int, Int] = {
case x if x > 0 => x * 100
}
```

The above partial function gets an integer value as input and process it and returns another integer value. Here, we check the value is negative or not before applying multiple operation.

Consider that we have a list of numbers and want to multiply each value by value 100, then we can make use of the above function.

Partial functions can help us to get rid of any side effects for example avoiding the negative number in list.

Refer the below complete code and its output.

```
object ScalaExample {
//Partial function: MUltiply the input by 100 and return it.
val multiplyBy100: PartialFunction[Int, Int] = {
case x if x > 0 => x * 100
}
def main(args: Array[String]): Unit = {
//List of numbers
val numbers1 = List(1, 4, 5, 6, 7)
//Use the partial function and coll
println("numbers1::" + (numbers1 collect multiplyBy100))
//List contains negative numbers as well
val numbers2 = List(-1, -2, -3, 10)
println("numbers2::" + (numbers2 collect multiplyBy100))
}
}
```

```
numbers1::List(100, 400, 500, 600, 700)
numbers2::List(1000)
```

Scala’s PartialFunction trait contains the isDefinedAt method which can be called to check whether it handles the given value.

For example, We can call like this *multiplyBy100.isDefinedAt(-1)* which returns false. whereas this one *multiplyBy100.isDefinedAt(1)* returns true.