简体   繁体   English

Scala - 使用toMap时发散隐式扩展

[英]Scala - diverging implicit expansion when using toMap

I have the following definition of an enum: 我有一个枚举的以下定义:

object GraphType extends Enumeration {
  type Type = Value
  val MESSAGE, REQUEST, ERRORS = Value
}

Now I am trying to map each of the type to the corresponding, new TimeSeries as follows: 现在我尝试将每个类型映射到相应的新TimeSeries ,如下所示:

val dataSets = ( GraphType.values map (graphType => graphType -> new TimeSeries(graphType)) ).toMap

the type system lists datasets as Map[GraphType.Value, TimeSeries] which is precisely what I want. 类型系统将数据集列为Map[GraphType.Value, TimeSeries] ,这正是我想要的。 However, compilation fails with error message: 但是,编译失败并显示错误消息:

error: diverging implicit expansion for type scala.collection.generic.CanBuildFrom[ird.replay.gui.GraphType.ValueSet,(ird.replay.gui.GraphType.Value, org.jfree.data.time.TimeSeries),That]
starting with method newCanBuildFrom in object SortedSet
val dataSets = GraphType.values map (graphType => graphType -> new TimeSeries(graphType)) toMap

COuld anyone provide some explanation for this, rather cryptic, error message? 任何人都提供了一些解释,相当神秘,错误的消息? Thanks 谢谢

Try converting the Set of values for the enum to a List first like so: 尝试首先将枚举的值集转换为List如下所示:

val dataSets = (GraphType.values.toList.map(gt => (gt, new TimeSeries(gt)))).toMap

Something about that being a Set did not agree with how you were attempting to convert it to a Map , but it seems to work just fine with a List 关于那是一个Set的东西并不同意你是如何尝试将它转换为Map ,但它似乎与List

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM