Open NthPortal opened 4 years ago
Interesting. Was this done intentionally?
@scala/collections
I tested it with
But yes, it should , otherwise when programming with it, the type info is lost, have not checkout the scala/scala source code to check it out.
I tested it with
But yes, it should , otherwise when programming with it, the type info is lost, have not checkout the scala/scala source code to check it out.
It looks like scala3 has been fixed
Let's avoid posting pictures. Code in triple backquoted blocks for formatting. Then we can cut/paste your snippets. Thanks!
The OP claim was that it doesn't extend mutable.MapOps
:
final class TrieMap[K, V] extends mutable.AbstractMap[K, V] with Map[K, V] with mutable.MapOps[K, V, TrieMap, TrieMap[K, V]] with MapFactoryDefaults[K, V, TrieMap, mutable.Iterable] with DefaultSerializable
Surprisingly difficult to cut/paste from Scaladoc. I had to paste to a terminal to get it without links.
Anyway, the OP claim is not about TrieMap
.
scala> import collection.concurrent.TrieMap
import collection.concurrent.TrieMap
scala> val m = TrieMap("one"->1, "fortytwo"->42)
val m: scala.collection.concurrent.TrieMap[String,Int] = TrieMap(fortytwo -> 42, one -> 1)
scala> import collection.concurrent.{Map => CMap}
import collection.concurrent.{Map=>CMap}
scala> val cm: CMap[String, Int] = m
val cm: scala.collection.concurrent.Map[String,Int] = TrieMap(fortytwo -> 42, one -> 1)
scala> cm.filter { case (s, i) => s.startsWith("f") }
val res0: scala.collection.mutable.Map[String,Int] = TrieMap(fortytwo -> 42)
And so
scala> type Thing[K, V] = scala.collection.concurrent.Map[K, V] with scala.collection.mutable.MapOps[K, V, TrieMap, Trie
Map[K, V]]
type Thing
scala> val cm: Thing[String, Int] = m
val cm: Thing[String,Int] = TrieMap(fortytwo -> 42, one -> 1)
scala> cm.filter { case (s, i) => s.startsWith("f") }
val res2: scala.collection.concurrent.TrieMap[String,Int] = TrieMap(fortytwo -> 42)
scala> type Thing[K, V] = scala.collection.concurrent.Map[K, V] with scala.collection.mutable.MapOps[K, V, CMap, CMap[K,
V]]
^
error: type arguments [K,V,scala.collection.concurrent.Map,scala.collection.concurrent.Map[K,V]] do not conform to trait MapOps's type parameter bounds [K,V,+CC[X, Y] <: scala.collection.mutable.MapOps[X, Y, CC, _],+C <: scala.collection.mutable.MapOps[K,V,CC,C]]
concurrent.Map[K, V]
does not extendmutable.MapOps[K, V, concurrent.Map, concurrent.Map[K, V]]
, and thus its methods returnmutable.Map
or types based on the same. For example:filter
returns amutable.Map
rather than aconcurrent.Map
mapFactory
returns aMapFactory[mutable.Map]
rather than aMapFactory[concurrent.Map]