diff options
author | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-01-15 16:58:28 +0000 |
---|---|---|
committer | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-01-15 16:58:28 +0000 |
commit | 3e1241caeca9af5b05922d38bed1b0480e6da56d (patch) | |
tree | 56ab1c1e104498ce49ef57c86dd453143955b48d /src/library | |
parent | b0e6451e78740747da641d3c4b7f524f102810f9 (diff) | |
download | scala-3e1241caeca9af5b05922d38bed1b0480e6da56d.tar.gz scala-3e1241caeca9af5b05922d38bed1b0480e6da56d.tar.bz2 scala-3e1241caeca9af5b05922d38bed1b0480e6da56d.zip |
Reverted over-zealous replacement of 'PartialFu...
Reverted over-zealous replacement of 'PartialFunction' with '=>?'.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Option.scala | 2 | ||||
-rw-r--r-- | src/library/scala/PartialFunction.scala | 8 | ||||
-rw-r--r-- | src/library/scala/collection/Iterator.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/TraversableLike.scala | 4 | ||||
-rw-r--r-- | src/library/scala/collection/TraversableProxyLike.scala | 2 | ||||
-rw-r--r-- | src/library/scala/collection/interfaces/TraversableMethods.scala | 2 | ||||
-rw-r--r-- | src/library/scala/concurrent/MailBox.scala | 6 | ||||
-rw-r--r-- | src/library/scala/package.scala | 2 | ||||
-rw-r--r-- | src/library/scala/runtime/ScalaRunTime.scala | 4 | ||||
-rw-r--r-- | src/library/scala/util/control/Exception.scala | 14 | ||||
-rw-r--r-- | src/library/scala/util/parsing/combinator/Parsers.scala | 14 |
11 files changed, 29 insertions, 31 deletions
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala index 6cb0fec929..8511fa78a5 100644 --- a/src/library/scala/Option.scala +++ b/src/library/scala/Option.scala @@ -110,7 +110,7 @@ sealed abstract class Option[+A] extends Product { * * @param pf the partial function. */ - def partialMap[B](pf: A =>? B): Option[B] = + def partialMap[B](pf: PartialFunction[A, B]): Option[B] = if (!isEmpty && pf.isDefinedAt(this.get)) Some(pf(this.get)) else None /** If the option is nonempty return it, diff --git a/src/library/scala/PartialFunction.scala b/src/library/scala/PartialFunction.scala index f62fa68565..f450596e57 100644 --- a/src/library/scala/PartialFunction.scala +++ b/src/library/scala/PartialFunction.scala @@ -38,7 +38,7 @@ trait PartialFunction[-A, +B] extends (A => B) { * of this partial function and `that`. The resulting partial function * takes `x` to `this(x)` where `this` is defined, and to `that(x)` where it is not. */ - def orElse[A1 <: A, B1 >: B](that: A1 =>? B1) : A1 =>? B1 = + def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = new PartialFunction[A1, B1] { def isDefinedAt(x: A1): Boolean = PartialFunction.this.isDefinedAt(x) || that.isDefinedAt(x) @@ -54,7 +54,7 @@ trait PartialFunction[-A, +B] extends (A => B) { * @return a partial function with the same domain as this partial function, which maps * arguments `x` to `k(this(x))`. */ - override def andThen[C](k: B => C): A =>? C = new PartialFunction[A, C] { + override def andThen[C](k: B => C) : PartialFunction[A, C] = new PartialFunction[A, C] { def isDefinedAt(x: A): Boolean = PartialFunction.this.isDefinedAt(x) def apply(x: A): C = k(PartialFunction.this.apply(x)) } @@ -92,7 +92,7 @@ object PartialFunction * @param pf the partial function * @return true, iff `x` is in the domain of `pf` and `pf(x) == true`. */ - def cond[T](x: T)(pf: T =>? Boolean): Boolean = + def cond[T](x: T)(pf: PartialFunction[T, Boolean]): Boolean = (pf isDefinedAt x) && pf(x) /** Transforms a PartialFunction[T, U] `pf' into Function1[T, Option[U]] `f' @@ -104,6 +104,6 @@ object PartialFunction * @param pf the PartialFunction[T, U] * @return `Some(pf(x))` if `pf isDefinedAt x`, `None` otherwise. */ - def condOpt[T,U](x: T)(pf: T =>? U): Option[U] = + def condOpt[T,U](x: T)(pf: PartialFunction[T, U]): Option[U] = if (pf isDefinedAt x) Some(pf(x)) else None } diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index 6be99bf27c..c23765c9bc 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -411,7 +411,7 @@ trait Iterator[+A] { self => * @return a new iterator which yields each value `x` produced by this iterator for * which `pf` is defined the image `pf(x)`. */ - def partialMap[B](pf: A =>? B): Iterator[B] = { + def partialMap[B](pf: PartialFunction[A, B]): Iterator[B] = { val self = buffered new Iterator[B] { private def skip() = while (self.hasNext && !pf.isDefinedAt(self.head)) self.next() diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index a37341c2b5..fc666ddb92 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -292,13 +292,13 @@ self => * `pf` to each element on which it is defined and collecting the results. * The order of the elements is preserved. * - * @usecase def partialMap[B](pf: A =>? B): $Coll[B] + * @usecase def partialMap[B](pf: PartialFunction[A, B]): $Coll[B] * * @return a new $coll resulting from applying the given partial function * `pf` to each element on which it is defined and collecting the results. * The order of the elements is preserved. */ - def partialMap[B, That](pf: A =>? B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { + def partialMap[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- this) if (pf.isDefinedAt(x)) b += pf(x) b.result diff --git a/src/library/scala/collection/TraversableProxyLike.scala b/src/library/scala/collection/TraversableProxyLike.scala index d8e3ed2a1b..24d6c7048d 100644 --- a/src/library/scala/collection/TraversableProxyLike.scala +++ b/src/library/scala/collection/TraversableProxyLike.scala @@ -36,7 +36,7 @@ trait TraversableProxyLike[+A, +This <: TraversableLike[A, This] with Traversabl override def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[This, B, That]): That = self.++(that)(bf) override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That = self.map(f)(bf) override def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That = self.flatMap(f)(bf) - override def partialMap[B, That](pf: A =>? B)(implicit bf: CanBuildFrom[This, B, That]): That = self.partialMap(pf)(bf) + override def partialMap[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[This, B, That]): That = self.partialMap(pf)(bf) override def filter(p: A => Boolean): This = self.filter(p) override def filterNot(p: A => Boolean): This = self.filterNot(p) override def partition(p: A => Boolean): (This, This) = self.partition(p) diff --git a/src/library/scala/collection/interfaces/TraversableMethods.scala b/src/library/scala/collection/interfaces/TraversableMethods.scala index 4cf133d36a..08ade7586d 100644 --- a/src/library/scala/collection/interfaces/TraversableMethods.scala +++ b/src/library/scala/collection/interfaces/TraversableMethods.scala @@ -24,7 +24,7 @@ trait TraversableMethods[+A, +This <: TraversableLike[A, This] with Traversable[ // maps/iteration def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That - def partialMap[B, That](pf: A =>? B)(implicit bf: CanBuildFrom[This, B, That]): That + def partialMap[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[This, B, That]): That // new collections def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[This, B, That]): That diff --git a/src/library/scala/concurrent/MailBox.scala b/src/library/scala/concurrent/MailBox.scala index 3b00d6165d..c23bbf1c80 100644 --- a/src/library/scala/concurrent/MailBox.scala +++ b/src/library/scala/concurrent/MailBox.scala @@ -26,7 +26,7 @@ class MailBox extends AnyRef with ListQueueCreator { def isDefinedAt(msg: Message): Boolean } - private class Receiver[A](receiver: Message =>? A) extends PreReceiver { + private class Receiver[A](receiver: PartialFunction[Message, A]) extends PreReceiver { def isDefinedAt(msg: Message) = receiver.isDefinedAt(msg) @@ -85,7 +85,7 @@ class MailBox extends AnyRef with ListQueueCreator { * Block until there is a message in the mailbox for which the processor * <code>f</code> is defined. */ - def receive[A](f: Message =>? A): A = { + def receive[A](f: PartialFunction[Message, A]): A = { val r = new Receiver(f) scanSentMsgs(r) r.receive() @@ -95,7 +95,7 @@ class MailBox extends AnyRef with ListQueueCreator { * Block until there is a message in the mailbox for which the processor * <code>f</code> is defined or the timeout is over. */ - def receiveWithin[A](msec: Long)(f: Message =>? A): A = { + def receiveWithin[A](msec: Long)(f: PartialFunction[Message, A]): A = { val r = new Receiver(f) scanSentMsgs(r) r.receiveWithin(msec) diff --git a/src/library/scala/package.scala b/src/library/scala/package.scala index d67b106eb0..9fa09e3b72 100644 --- a/src/library/scala/package.scala +++ b/src/library/scala/package.scala @@ -64,8 +64,6 @@ package object scala { type Range = scala.collection.immutable.Range val Range = scala.collection.immutable.Range - @deprecated("use PartialFunction instead") type =>? [-A, +B] = PartialFunction[A, B] - // Migrated from Predef val $scope = scala.xml.TopScope diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index ebce675347..ecc81c074e 100644 --- a/src/library/scala/runtime/ScalaRunTime.scala +++ b/src/library/scala/runtime/ScalaRunTime.scala @@ -100,7 +100,7 @@ object ScalaRunTime { if (x == null) throw new UninitializedError else x abstract class Try[+A] { - def Catch[B >: A](handler: Throwable =>? B): B + def Catch[B >: A](handler: PartialFunction[Throwable, B]): B def Finally(fin: => Unit): A } @@ -115,7 +115,7 @@ object ScalaRunTime { def run() { result = block } - def Catch[B >: A](handler: Throwable =>? B): B = + def Catch[B >: A](handler: PartialFunction[Throwable, B]): B = if (exception == null) result else if (handler isDefinedAt exception) handler(exception) else throw exception diff --git a/src/library/scala/util/control/Exception.scala b/src/library/scala/util/control/Exception.scala index 67f9ec183b..356b11df51 100644 --- a/src/library/scala/util/control/Exception.scala +++ b/src/library/scala/util/control/Exception.scala @@ -23,14 +23,14 @@ object Exception // We get lots of crashes using this, so for now we just use Class[_] // type ExClass = Class[_ <: Throwable] - type Catcher[+T] = Throwable =>? T - type ExceptionCatcher[+T] = Exception =>? T + type Catcher[+T] = PartialFunction[Throwable, T] + type ExceptionCatcher[+T] = PartialFunction[Exception, T] // due to the magic of contravariance, Throwable => T is a subtype of // Exception => T, not the other way around. So we manually construct // a Throwable => T and simply rethrow the non-Exceptions. implicit def fromExceptionCatcher[T](pf: ExceptionCatcher[T]): Catcher[T] = { - new (Throwable =>? T) { + new PartialFunction[Throwable, T] { def isDefinedAt(x: Throwable) = x match { case e: Exception if pf.isDefinedAt(e) => true case _ => false @@ -101,7 +101,7 @@ object Exception /** Create a new Catch with the same isDefinedAt logic as this one, * but with the supplied apply method replacing the current one. */ def withApply[U](f: (Throwable) => U): Catch[U] = { - val pf2 = new (Throwable =>? U) { + val pf2 = new PartialFunction[Throwable, U] { def isDefinedAt(x: Throwable) = pf isDefinedAt x def apply(x: Throwable) = f(x) } @@ -139,8 +139,8 @@ object Exception override def toString() = List("Try(<body>)", catcher.toString) mkString " " } - final val nothingCatcher: Throwable =>? Nothing = - new (Throwable =>? Nothing) { + final val nothingCatcher: PartialFunction[Throwable, Nothing] = + new PartialFunction[Throwable, Nothing] { def isDefinedAt(x: Throwable) = false def apply(x: Throwable) = throw x } @@ -207,7 +207,7 @@ object Exception classes exists (_ isAssignableFrom x.getClass) private def pfFromExceptions(exceptions: Class[_]*) = - new (Throwable =>? Nothing) { + new PartialFunction[Throwable, Nothing] { def apply(x: Throwable) = throw x def isDefinedAt(x: Throwable) = wouldMatch(x, exceptions) } diff --git a/src/library/scala/util/parsing/combinator/Parsers.scala b/src/library/scala/util/parsing/combinator/Parsers.scala index 1205d2f911..3aa7cc7de1 100644 --- a/src/library/scala/util/parsing/combinator/Parsers.scala +++ b/src/library/scala/util/parsing/combinator/Parsers.scala @@ -93,7 +93,7 @@ trait Parsers { * `f' applied to the result of this `ParseResult', packaged up as a new `ParseResult'. * If `f' is not defined, `Failure'. */ - def mapPartial[U](f: T =>? U, error: T => String): ParseResult[U] + def mapPartial[U](f: PartialFunction[T, U], error: T => String): ParseResult[U] def flatMapWithNext[U](f: T => Input => ParseResult[U]): ParseResult[U] @@ -119,7 +119,7 @@ trait Parsers { */ case class Success[+T](result: T, override val next: Input) extends ParseResult[T] { def map[U](f: T => U) = Success(f(result), next) - def mapPartial[U](f: T =>? U, error: T => String): ParseResult[U] + def mapPartial[U](f: PartialFunction[T, U], error: T => String): ParseResult[U] = if(f.isDefinedAt(result)) Success(f(result), next) else Failure(error(result), next) @@ -146,7 +146,7 @@ trait Parsers { lastNoSuccess = this def map[U](f: Nothing => U) = this - def mapPartial[U](f: Nothing =>? U, error: Nothing => String): ParseResult[U] = this + def mapPartial[U](f: PartialFunction[Nothing, U], error: Nothing => String): ParseResult[U] = this def flatMapWithNext[U](f: Nothing => Input => ParseResult[U]): ParseResult[U] = this @@ -345,7 +345,7 @@ trait Parsers { * @return a parser that succeeds if the current parser succeeds <i>and</i> `f' is applicable * to the result. If so, the result will be transformed by `f'. */ - def ^? [U](f: T =>? U, error: T => String): Parser[U] = Parser{ in => + def ^? [U](f: PartialFunction[T, U], error: T => String): Parser[U] = Parser{ in => this(in).mapPartial(f, error)}.named(toString+"^?") /** A parser combinator for partial function application @@ -358,7 +358,7 @@ trait Parsers { * @return a parser that succeeds if the current parser succeeds <i>and</i> `f' is applicable * to the result. If so, the result will be transformed by `f'. */ - def ^? [U](f: T =>? U): Parser[U] = ^?(f, r => "Constructor function not defined at "+r) + def ^? [U](f: PartialFunction[T, U]): Parser[U] = ^?(f, r => "Constructor function not defined at "+r) /** A parser combinator that parameterises a subsequent parser with the result of this one @@ -495,7 +495,7 @@ trait Parsers { * @return A parser that succeeds if `f' is applicable to the first element of the input, * applying `f' to it to produce the result. */ - def accept[U](expected: String, f: Elem =>? U): Parser[U] = acceptMatch(expected, f) + def accept[U](expected: String, f: PartialFunction[Elem, U]): Parser[U] = acceptMatch(expected, f) def acceptIf(p: Elem => Boolean)(err: Elem => String): Parser[Elem] = Parser { in => @@ -503,7 +503,7 @@ trait Parsers { else Failure(err(in.first), in) } - def acceptMatch[U](expected: String, f: Elem =>? U): Parser[U] = Parser{ in => + def acceptMatch[U](expected: String, f: PartialFunction[Elem, U]): Parser[U] = Parser{ in => if (f.isDefinedAt(in.first)) Success(f(in.first), in.rest) else Failure(expected+" expected", in) } |