diff options
author | Paul Phillips <paulp@improving.org> | 2009-12-22 20:11:29 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-12-22 20:11:29 +0000 |
commit | 361a7a40d35e09d7f622fcafd28531172a139e0e (patch) | |
tree | 53047ba64d5b56cc75b8b67500ad346c398437d6 /src/library | |
parent | d32b5bc758e9203ed66b2517d2abc2530385c1dc (diff) | |
download | scala-361a7a40d35e09d7f622fcafd28531172a139e0e.tar.gz scala-361a7a40d35e09d7f622fcafd28531172a139e0e.tar.bz2 scala-361a7a40d35e09d7f622fcafd28531172a139e0e.zip |
Took full advantage of the new =>? alias for th...
Took full advantage of the new =>? alias for the superverbosely named
PartialFunction by renaming every usage of the latter except when in
comments.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Option.scala | 2 | ||||
-rw-r--r-- | src/library/scala/PartialFunction.scala | 12 | ||||
-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/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 |
10 files changed, 31 insertions, 31 deletions
diff --git a/src/library/scala/Option.scala b/src/library/scala/Option.scala index 8511fa78a5..6cb0fec929 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: PartialFunction[A, B]): Option[B] = + def partialMap[B](pf: 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 81ca2e4e10..f62fa68565 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: PartialFunction[A1, B1]) : PartialFunction[A1, B1] = + def orElse[A1 <: A, B1 >: B](that: A1 =>? B1) : 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) : PartialFunction[A, C] = new PartialFunction[A, C] { + override def andThen[C](k: B => C): 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,18 +92,18 @@ 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: PartialFunction[T, Boolean]): Boolean = + def cond[T](x: T)(pf: T =>? Boolean): Boolean = (pf isDefinedAt x) && pf(x) - /** Transforms a PartialFunction[T,U] `pf' into Function1[T, Option[U]] `f' + /** Transforms a PartialFunction[T, U] `pf' into Function1[T, Option[U]] `f' * whose result is Some(x) if the argument is in pf's domain and None otherwise, * and applies it to the value `x'. In effect, it is a 'match' statement * which wraps all case results in Some(_) and adds 'case _ => None' to the end. * * @param x the value to test - * @param pf the PartialFunction[T,U] + * @param pf the PartialFunction[T, U] * @return `Some(pf(x))` if `pf isDefinedAt x`, `None` otherwise. */ - def condOpt[T,U](x: T)(pf: PartialFunction[T, U]): Option[U] = + def condOpt[T,U](x: T)(pf: 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 54a38848dd..5f28161ed3 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: PartialFunction[A, B]): Iterator[B] = { + def partialMap[B](pf: 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 8c8f619b5e..f570c4ca9a 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: PartialFunction[A, B]): $Coll[B] + * @usecase def partialMap[B](pf: 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: PartialFunction[A, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { + def partialMap[B, That](pf: 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 24d6c7048d..d8e3ed2a1b 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: PartialFunction[A, B])(implicit bf: CanBuildFrom[This, B, That]): That = self.partialMap(pf)(bf) + override def partialMap[B, That](pf: 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 08ade7586d..4cf133d36a 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: PartialFunction[A, B])(implicit bf: CanBuildFrom[This, B, That]): That + def partialMap[B, That](pf: 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 c23bbf1c80..3b00d6165d 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: PartialFunction[Message, A]) extends PreReceiver { + private class Receiver[A](receiver: 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: PartialFunction[Message, A]): A = { + def receive[A](f: 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: PartialFunction[Message, A]): A = { + def receiveWithin[A](msec: Long)(f: Message =>? A): A = { val r = new Receiver(f) scanSentMsgs(r) r.receiveWithin(msec) diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala index ecc81c074e..ebce675347 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: PartialFunction[Throwable, B]): B + def Catch[B >: A](handler: Throwable =>? B): B def Finally(fin: => Unit): A } @@ -115,7 +115,7 @@ object ScalaRunTime { def run() { result = block } - def Catch[B >: A](handler: PartialFunction[Throwable, B]): B = + def Catch[B >: A](handler: 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 356b11df51..67f9ec183b 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] = PartialFunction[Throwable, T] - type ExceptionCatcher[+T] = PartialFunction[Exception, T] + type Catcher[+T] = Throwable =>? T + type ExceptionCatcher[+T] = 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 PartialFunction[Throwable, T] { + new (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 PartialFunction[Throwable, U] { + val pf2 = new (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: PartialFunction[Throwable, Nothing] = - new PartialFunction[Throwable, Nothing] { + final val nothingCatcher: Throwable =>? Nothing = + new (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 PartialFunction[Throwable, Nothing] { + new (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 3aa7cc7de1..1205d2f911 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: PartialFunction[T, U], error: T => String): ParseResult[U] + def mapPartial[U](f: 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: PartialFunction[T, U], error: T => String): ParseResult[U] + def mapPartial[U](f: 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: PartialFunction[Nothing, U], error: Nothing => String): ParseResult[U] = this + def mapPartial[U](f: 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: PartialFunction[T, U], error: T => String): Parser[U] = Parser{ in => + def ^? [U](f: 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: PartialFunction[T, U]): Parser[U] = ^?(f, r => "Constructor function not defined at "+r) + def ^? [U](f: 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: PartialFunction[Elem, U]): Parser[U] = acceptMatch(expected, f) + def accept[U](expected: String, f: 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: PartialFunction[Elem, U]): Parser[U] = Parser{ in => + def acceptMatch[U](expected: String, f: Elem =>? U): Parser[U] = Parser{ in => if (f.isDefinedAt(in.first)) Success(f(in.first), in.rest) else Failure(expected+" expected", in) } |