- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Mapping maps
Mon, 2009-06-01, 12:12
More implicit resolution errors:
scala> TreeMap(1 -> 2)
res0: scala.collection.immutable.TreeMap[Int,Int] = Map(1 -> 2)
scala> res0.map(_.toString)
res1: scala.collection.immutable.Iterable[String] = List((1,2))
scala> res0.map(x => x)
:9: error: ambiguous implicit values:
both method builderFactory in object TreeMap of type [A,B](implicit
ord: Ordering[A])scala.collection.generic.BuilderFactory[(A,
B),scala.collection.immutable.TreeMap[A,B],scala.collection.immutable.TreeMap#Coll]
and method builderFactory in object Traversable of type
[A]scala.collection.generic.BuilderFactory[A,scala.collection.immutab...
res0.map(x => x)
^
This seems to be a specific problem with TreeMap, either because of
ordering or because of defining methods in the companion object:
scala> IntMap(1 -> 2)
res4: scala.collection.immutable.IntMap[Int] = IntMap(1 -> 2)
scala> res4.map(x => x)
res5: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2)
scala> HashMap(1 -> 2)
res6: scala.collection.immutable.HashMap[Int,Int] = Map(1 -> 2)
scala> res6.map(x => x)
res7: scala.collection.immutable.HashMap[Int,Int] = Map(1 -> 2)