@_felipera

Partial function is very useful

Scala

Medium
Functional Pills # 15- Partial Functions
Here, divide is a basic partial function, handling integer inputs. The isDefinedAt method helps check of the function is ready to handle a particular value.
For instance, the divide function, which is not defined at the Int value zero, may explode with a MatchError when used with the map method: List(0, 1, 2) map { divide }// scala.MatchError: 0 (of class java.lang.Integer)// stack trace continues ...
However, using the collect method with the same function works seamlessly: List(0, 1, 2) collect { divide }// res0: List[Int] = List(42, 21)
[ post ]