Add mapValues for Scala 2.12 collection compat
This commit is contained in:
parent
fbada2cf16
commit
33583e027b
2 changed files with 20 additions and 1 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
package org.apache.pekko.util
|
package org.apache.pekko.util
|
||||||
|
|
||||||
import scala.{ collection => c }
|
import scala.{ collection => c }
|
||||||
import scala.collection.{ immutable => i, mutable => m, GenTraversable }
|
import scala.collection.{ immutable => i, mutable => m, GenTraversable, IterableView }
|
||||||
import scala.collection.generic.{ CanBuildFrom, GenericCompanion, Sorted, SortedSetFactory }
|
import scala.collection.generic.{ CanBuildFrom, GenericCompanion, Sorted, SortedSetFactory }
|
||||||
import scala.language.higherKinds
|
import scala.language.higherKinds
|
||||||
import scala.language.implicitConversions
|
import scala.language.implicitConversions
|
||||||
|
|
@ -88,6 +88,10 @@ package object ccompat {
|
||||||
type IterableOnce[+X] = c.TraversableOnce[X]
|
type IterableOnce[+X] = c.TraversableOnce[X]
|
||||||
val IterableOnce = c.TraversableOnce
|
val IterableOnce = c.TraversableOnce
|
||||||
|
|
||||||
|
implicit def toMapViewExtensionMethods[K, V, C <: scala.collection.Map[K, V]](
|
||||||
|
self: IterableView[(K, V), C]): MapViewExtensionMethods[K, V, C] =
|
||||||
|
new MapViewExtensionMethods[K, V, C](self)
|
||||||
|
|
||||||
implicit class ImmutableSortedSetOps[A](val real: i.SortedSet[A]) extends AnyVal {
|
implicit class ImmutableSortedSetOps[A](val real: i.SortedSet[A]) extends AnyVal {
|
||||||
def unsorted: i.Set[A] = real
|
def unsorted: i.Set[A] = real
|
||||||
}
|
}
|
||||||
|
|
@ -101,3 +105,9 @@ package object ccompat {
|
||||||
class TraversableOnceExtensionMethods[A](private val self: c.TraversableOnce[A]) extends AnyVal {
|
class TraversableOnceExtensionMethods[A](private val self: c.TraversableOnce[A]) extends AnyVal {
|
||||||
def iterator: Iterator[A] = self.toIterator
|
def iterator: Iterator[A] = self.toIterator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) }
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,12 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* license agreements; and to You under the Apache License, version 2.0:
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* This file is part of the Apache Pekko project, derived from Akka.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2021-2022 Lightbend Inc. <https://www.lightbend.com>
|
* Copyright (C) 2021-2022 Lightbend Inc. <https://www.lightbend.com>
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue