As others noted, PartialFunction.apply
converts an ordinary function into a partial function.
The only reasonable way to do this, since the domain of the ordinary function is unknown (as far as PartialFunction.apply
is concerned), is to create a partial function defined everywhere.
So when you write PartialFunction[Any,Unit] { case "a" => println("AAA") }
, you're actually creating two partial functions: the one passed into the apply
method and the one returned by the apply
method. They're almost the same, except that the returned function is defined everywhere and not just at "a"
.