diff options
author | Paul Phillips <paulp@improving.org> | 2011-08-28 00:13:17 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-08-28 00:13:17 +0000 |
commit | 6f881202be35c7d08ca73054594618cef19d8938 (patch) | |
tree | 144718e5f3b81247db3c3bbc197a397250079fe0 /src/library | |
parent | caaf4296681e4fa040d691169c6665d7b5eac9d2 (diff) | |
download | scala-6f881202be35c7d08ca73054594618cef19d8938.tar.gz scala-6f881202be35c7d08ca73054594618cef19d8938.tar.bz2 scala-6f881202be35c7d08ca73054594618cef19d8938.zip |
Gave partial function an empty member.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/PartialFunction.scala | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/library/scala/PartialFunction.scala b/src/library/scala/PartialFunction.scala index b8e20c2de1..51bb3dc93e 100644 --- a/src/library/scala/PartialFunction.scala +++ b/src/library/scala/PartialFunction.scala @@ -81,8 +81,15 @@ trait PartialFunction[-A, +B] extends (A => B) { * @author Paul Phillips * @since 2.8 */ -object PartialFunction -{ +object PartialFunction { + private[this] final val empty_pf = new PartialFunction[Any, Nothing] { + def isDefinedAt(x: Any) = false + def apply(x: Any): Nothing = sys.error("undefined") + override def orElse[A1, B1](that: PartialFunction[A1, B1]): PartialFunction[A1, B1] = that + override def lift = (x: Any) => None + } + def empty[A, B] : PartialFunction[A, B] = empty_pf.asInstanceOf[PartialFunction[A, B]] + /** Creates a Boolean test based on a value and a partial function. * It behaves like a 'match' statement with an implied 'case _ => false' * following the supplied cases. |