From 83520220541c0ff8e3c9f9efde10f90b963e679f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 11 Mar 2010 17:11:24 +0000 Subject: Partially reverted r21018. --- src/library/scala/collection/MapLike.scala | 46 ++++++++-------------- .../scala/collection/immutable/MapLike.scala | 12 ++++++ 2 files changed, 29 insertions(+), 29 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/collection/MapLike.scala b/src/library/scala/collection/MapLike.scala index 2ca41319f3..8806098aa4 100644 --- a/src/library/scala/collection/MapLike.scala +++ b/src/library/scala/collection/MapLike.scala @@ -255,35 +255,6 @@ self => @deprecated("use `mapValues' instead") def mapElements[C](f: B => C) = mapValues(f) - /** This function transforms all the values of mappings contained - * in this map with function f. - * - * @param f A function over keys and values - * @return the updated map - */ - def transform[C, That](f: (A, B) => C)(implicit bf: CanBuildFrom[This, (A, C), That]): That = { - val b = bf(repr) - for ((key, value) <- this) b += ((key, f(key, value))) - b.result - } - - /** Returns a new map with all key/value pairs for which the predicate - * p returns false. - * - * @param p A predicate over key-value pairs - * @note This method works by successively removing elements fro which the - * predicate is true from this set. - * If removal is slow, or you expect that most elements of the set$ - * will be removed, you might consider using filter - * with a negated predicate instead. - */ - override def filterNot(p: ((A, B)) => Boolean): This = { - var res: This = repr - for (kv <- this) - if (p(kv)) res = (res - kv._1).asInstanceOf[This] // !!! concrete overrides abstract problem - res - } - // The following 5 operations (updated, two times +, two times ++) should really be // generic, returning This[B]. We need better covariance support to express that though. // So right now we do the brute force approach of code duplication. @@ -333,6 +304,23 @@ self => def ++[B1 >: B] (iter: Iterator[(A, B1)]): Map[A, B1] = ((repr: Map[A, B1]) /: iter) (_ + _) + /** Returns a new map with all key/value pairs for which the predicate + * p returns true. + * + * @param p A predicate over key-value pairs + * @note This method works by successively removing elements fro which the + * predicate is false from this set. + * If removal is slow, or you expect that most elements of the set$ + * will be removed, you might consider using filter + * with a negated predicate instead. + */ + override def filterNot(p: ((A, B)) => Boolean): This = { + var res: This = repr + for (kv <- this) + if (p(kv)) res = (res - kv._1).asInstanceOf[This] // !!! concrete overrides abstract problem + res + } + /** Appends all bindings of this map to a string builder using start, end, and separator strings. * The written text begins with the string `start` and ends with the string * `end`. Inside, the string representations of all bindings of this map diff --git a/src/library/scala/collection/immutable/MapLike.scala b/src/library/scala/collection/immutable/MapLike.scala index 88f938fb56..f669268a88 100644 --- a/src/library/scala/collection/immutable/MapLike.scala +++ b/src/library/scala/collection/immutable/MapLike.scala @@ -113,6 +113,18 @@ self => def get(key: A) = self.get(key).map(f) } + /** This function transforms all the values of mappings contained + * in this map with function f. + * + * @param f A function over keys and values + * @return the updated map + */ + def transform[C, That](f: (A, B) => C)(implicit bf: CanBuildFrom[This, (A, C), That]): That = { + val b = bf(repr) + for ((key, value) <- this) b += ((key, f(key, value))) + b.result + } + @deprecated("use `updated' instead") def update[B1 >: B](key: A, value: B1): immutable.Map[A, B1] = updated(key, value).asInstanceOf[immutable.Map[A, B1]] } -- cgit v1.2.3