There is much confusion about PartialFunction vs Function1, and I believe this is caused by lack of documentation. Specifically, the following mail from Martin Odersky is not reflected in Function1/PartialFunction ScalaDocs, as of 2.9.1:
Specifically, Function1 ScalaDocs should explain that the domain is not specified, while PartialFunction ScalaDocs should explain that the domain is now specified, and should clarify (once and for all) whether PartialFunction.apply is allowed to throw exceptions on the domain. In particular, I believe that it should be allowed, otherwise the following code should become illegal:
val f: PartialFunction[Int, Any] =
(it compiles on Scala 2.9.1 REPL).
Aaron Novstrup* suggested that whenever PartialFunction.apply throws an exception, that exception must be "part of the design of the function (and should be documented)", which makes sense.
- The issue was originally discussed between me (Blaisorblade) and Aaron Novstrup here: