diff options
author | Paul Phillips <paulp@improving.org> | 2009-05-19 12:51:16 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-05-19 12:51:16 +0000 |
commit | 14fb2dfadd8ef9b433fed2599c1b32049d4c90e2 (patch) | |
tree | 6755dace48145a0a54f63c84189059c6da7d6ba7 | |
parent | af9090a32aeb2a6db80767ae3ef10c484c63617d (diff) | |
download | scala-14fb2dfadd8ef9b433fed2599c1b32049d4c90e2.tar.gz scala-14fb2dfadd8ef9b433fed2599c1b32049d4c90e2.tar.bz2 scala-14fb2dfadd8ef9b433fed2599c1b32049d4c90e2.zip |
Reverting 17770 - right, that is what "map view...
Reverting 17770 - right, that is what "map view" means.
-rw-r--r-- | src/library/scala/collection/generic/MapTemplate.scala | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/library/scala/collection/generic/MapTemplate.scala b/src/library/scala/collection/generic/MapTemplate.scala index 4f4830d65c..a3260cc9b0 100644 --- a/src/library/scala/collection/generic/MapTemplate.scala +++ b/src/library/scala/collection/generic/MapTemplate.scala @@ -162,7 +162,12 @@ self => /** A map view consisting only of those key value pairs where the key satisfies a given * predicate `p`. */ - def filterKeys(p: A => Boolean): This = this filter (kv => p(kv._1)) + def filterKeys(p: A => Boolean) = new DefaultMap[A, B] { + override def foreach[C](f: ((A, B)) => C): Unit = for (kv <- self) if (p(kv._1)) f(kv) + def elements = self.elements.filter(kv => p(kv._1)) + override def contains(key: A) = self.contains(key) && p(key) + def get(key: A) = if (!p(key)) None else self.get(key) + } /** A map view resulting from applying a given function `f` to each value. */ |