diff --git a/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala b/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala index e2ce485b..76382afa 100644 --- a/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala +++ b/compat/src/main/scala-2.11_2.12/scala/collection/compat/PackageShared.scala @@ -246,7 +246,12 @@ class TraversableExtensionMethods[A](private val self: c.Traversable[A]) extends class MapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]]( private val self: IterableView[(K, V), C]) extends AnyVal { + def mapValues[W, That](f: V => W)( implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, W), That]): That = self.map[(K, W), That] { case (k, v) => (k, f(v)) } + + def filterKeys[That](p: K => Boolean)( + implicit bf: CanBuildFrom[IterableView[(K, V), C], (K, V), That]): That = + self.collect[(K, V), That] { case (k, v) if p(k) => (k, v) } } diff --git a/compat/src/test/scala/test/scala/collection/ViewTest.scala b/compat/src/test/scala/test/scala/collection/ViewTest.scala index 7e080863..7c150fc4 100644 --- a/compat/src/test/scala/test/scala/collection/ViewTest.scala +++ b/compat/src/test/scala/test/scala/collection/ViewTest.scala @@ -27,4 +27,12 @@ class ViewTest { assertEquals(oldStyle.toMap, newStyle.toMap) } + @Test + def filterKeys: Unit = { + val m = Map("a" -> 1, "b" -> 2, "c" -> 3) + val oldStyle = m.filterKeys(_ > "a") + val newStyle = m.view.filterKeys(_ > "a") + assertEquals(oldStyle.toMap, newStyle.toMap) + } + }