Skip to content

Commit

Permalink
[backport] Update PartialFunction documentation to include the fact t…
Browse files Browse the repository at this point in the history
…hat the caller is responsible for checking 'isDefinedAt'

(cherry picked from commit f7d2cec)
  • Loading branch information
Max Bileschi authored and gourlaysama committed Aug 11, 2014
1 parent 5321b1b commit f7e7f70
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/library/scala/PartialFunction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ package scala
/** A partial function of type `PartialFunction[A, B]` is a unary function
* where the domain does not necessarily include all values of type `A`.
* The function `isDefinedAt` allows to test dynamically if a value is in
* the domain of the function.
* the domain of the function.
*
* Even if `isDefinedAt` returns true for an `a: A`, calling `apply(a)` may
* still throw an exception, so the following code is legal:
*
* {{{
* val f: PartialFunction[Int, Any] = { case _ => 1/0 }
* }}}
*
* It is the responsibility of the caller of `apply` to check for membership
* in the domain by calling `isDefinedAt`, to ensure sanity of return values.
* A notable exception to this rule is `PartialFunction`s created with curly
* braces and case statements; In this case, a [[scala.MatchError]] is
* thrown if `isDefinedAt` (i.e. pattern matching) fails.
*
* The main distinction between `PartialFunction` and [[scala.Function1]] is
* that the user of a `PartialFunction` may choose to do something different
Expand Down

0 comments on commit f7e7f70

Please sign in to comment.