summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorAntonio Cunei <antonio.cunei@epfl.ch>2009-11-09 16:13:33 +0000
committerAntonio Cunei <antonio.cunei@epfl.ch>2009-11-09 16:13:33 +0000
commite981bccdb7874726af0896efdadb5e192d25c14a (patch)
tree68ec4c2c9764a935c7efd72cf00a7206b6e18166 /src/library
parentdf502f4ffa5ebf83e7e97a270504202e00f512ec (diff)
downloadscala-e981bccdb7874726af0896efdadb5e192d25c14a.tar.gz
scala-e981bccdb7874726af0896efdadb5e192d25c14a.tar.bz2
scala-e981bccdb7874726af0896efdadb5e192d25c14a.zip
Adds isDefinedAt to Function1. As a consequence,
code that mixes in PartialFunction now have to define isDefinedAt as override. Fixes #2225.
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/Function1.scala6
-rw-r--r--src/library/scala/PartialFunction.scala11
-rw-r--r--src/library/scala/collection/MapLike.scala2
-rw-r--r--src/library/scala/collection/SeqLike.scala4
-rw-r--r--src/library/scala/util/control/Exception.scala8
5 files changed, 15 insertions, 16 deletions
diff --git a/src/library/scala/Function1.scala b/src/library/scala/Function1.scala
index 7cfd32304e..80fe7ad1b6 100644
--- a/src/library/scala/Function1.scala
+++ b/src/library/scala/Function1.scala
@@ -47,4 +47,10 @@ trait Function1[-T1, +R] extends AnyRef { self =>
*/
def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) }
+ /** 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: T1): Boolean = true
}
diff --git a/src/library/scala/PartialFunction.scala b/src/library/scala/PartialFunction.scala
index 0ba7527976..1eb5f89fa4 100644
--- a/src/library/scala/PartialFunction.scala
+++ b/src/library/scala/PartialFunction.scala
@@ -21,16 +21,9 @@ 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] {
- def isDefinedAt(x: A1): Boolean =
+ override 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)
@@ -38,7 +31,7 @@ trait PartialFunction[-A, +B] extends AnyRef with (A => B) {
}
override def andThen[C](k: B => C) : PartialFunction[A, C] = new PartialFunction[A, C] {
- def isDefinedAt(x: A): Boolean = PartialFunction.this.isDefinedAt(x)
+ override def isDefinedAt(x: A): Boolean = PartialFunction.this.isDefinedAt(x)
def apply(x: A): C = k(PartialFunction.this.apply(x))
}
}
diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala
index 3b188acab6..8c44c374ca 100644
--- a/src/library/scala/collection/MapLike.scala
+++ b/src/library/scala/collection/MapLike.scala
@@ -122,7 +122,7 @@ self =>
* @param key the key
* @return <code>true</code> iff there is a mapping for key in this map
*/
- def isDefinedAt(key: A) = contains(key)
+ override def isDefinedAt(key: A) = contains(key)
/** @return the keys of this map as a set. */
def keySet: Set[A] = new DefaultKeySet
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala
index 708764e958..3413cb8a07 100644
--- a/src/library/scala/collection/SeqLike.scala
+++ b/src/library/scala/collection/SeqLike.scala
@@ -109,7 +109,7 @@ object SeqLike {
* @version 1.0, 16/07/2003
* @since 2.8
*/
-trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self =>
+trait SeqLike[+A, +Repr] extends Function[Int, A] with IterableLike[A, Repr] { self =>
override protected[this] def thisCollection: Seq[A] = this.asInstanceOf[Seq[A]]
override protected[this] def toCollection(repr: Repr): Seq[A] = repr.asInstanceOf[Seq[A]]
@@ -147,7 +147,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self =>
/** Is this partial function defined for the index <code>x</code>?
*/
- def isDefinedAt(x: Int): Boolean = (x >= 0) && (x < length)
+ override def isDefinedAt(x: Int): Boolean = (x >= 0) && (x < length)
/** Returns length of longest segment starting from a start index `from`
* such that every element of the segment satisfies predicate `p`.
diff --git a/src/library/scala/util/control/Exception.scala b/src/library/scala/util/control/Exception.scala
index 356b11df51..8add16fb70 100644
--- a/src/library/scala/util/control/Exception.scala
+++ b/src/library/scala/util/control/Exception.scala
@@ -31,7 +31,7 @@ object Exception
// a Throwable => T and simply rethrow the non-Exceptions.
implicit def fromExceptionCatcher[T](pf: ExceptionCatcher[T]): Catcher[T] = {
new PartialFunction[Throwable, T] {
- def isDefinedAt(x: Throwable) = x match {
+ override def isDefinedAt(x: Throwable) = x match {
case e: Exception if pf.isDefinedAt(e) => true
case _ => false
}
@@ -102,7 +102,7 @@ object Exception
* but with the supplied apply method replacing the current one. */
def withApply[U](f: (Throwable) => U): Catch[U] = {
val pf2 = new PartialFunction[Throwable, U] {
- def isDefinedAt(x: Throwable) = pf isDefinedAt x
+ override def isDefinedAt(x: Throwable) = pf isDefinedAt x
def apply(x: Throwable) = f(x)
}
new Catch(pf2, fin)
@@ -141,7 +141,7 @@ object Exception
final val nothingCatcher: PartialFunction[Throwable, Nothing] =
new PartialFunction[Throwable, Nothing] {
- def isDefinedAt(x: Throwable) = false
+ override def isDefinedAt(x: Throwable) = false
def apply(x: Throwable) = throw x
}
@@ -209,6 +209,6 @@ object Exception
private def pfFromExceptions(exceptions: Class[_]*) =
new PartialFunction[Throwable, Nothing] {
def apply(x: Throwable) = throw x
- def isDefinedAt(x: Throwable) = wouldMatch(x, exceptions)
+ override def isDefinedAt(x: Throwable) = wouldMatch(x, exceptions)
}
}