This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Mapping maps

No replies
DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.

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)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland