diff options
Diffstat (limited to 'src/library/scala/PartialFunction.scala')
-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 1eb5f89fa4..0ba7527976 100644 --- a/src/library/scala/PartialFunction.scala +++ b/src/library/scala/PartialFunction.scala @@ -21,9 +21,16 @@ package scala */ trait PartialFunction[-A, +B] extends AnyRef with (A => B) { + /** Checks if a value is contained in the functions domain. + * + * @param x the value to test + * @return true, iff <code>x</code> is in the domain of this function. + */ + def isDefinedAt(x: A): Boolean + def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = new PartialFunction[A1, B1] { - override def isDefinedAt(x: A1): Boolean = + def isDefinedAt(x: A1): Boolean = PartialFunction.this.isDefinedAt(x) || that.isDefinedAt(x) def apply(x: A1): B1 = if (PartialFunction.this.isDefinedAt(x)) PartialFunction.this.apply(x) @@ -31,7 +38,7 @@ trait PartialFunction[-A, +B] extends AnyRef with (A => B) { } override def andThen[C](k: B => C) : PartialFunction[A, C] = new PartialFunction[A, C] { - override def isDefinedAt(x: A): Boolean = PartialFunction.this.isDefinedAt(x) + def isDefinedAt(x: A): Boolean = PartialFunction.this.isDefinedAt(x) def apply(x: A): C = k(PartialFunction.this.apply(x)) } } |