gpt4 book ai didi

scala - Scala集合中缺少par方法

转载 作者:行者123 更新时间:2023-12-01 15:00:59 25 4
gpt4 key购买 nike

我试图在Intellij中将顺序列表转换为并行列表,但出现错误

Cannot resolve symbol par



.par方法调用上:
import scala.collection.parallel.immutable._
...
val parList = List(1,2,3).par

根据 https://docs.scala-lang.org/overviews/parallel-collections/overview.html,一个人必须简单地

invoke the par method on the sequential collection, list. After that, one can use a parallel collection in the same way one would normally use a sequential collection.



让我感到奇怪的是,我在scala的当前不可变列表api中没有找到任何 par方法: https://www.scala-lang.org/api/current/scala/collection/immutable/List.html

但是,甚至还有一个专用的scala文档页面,用于使用 par方法的顺序到并行转换: https://docs.scala-lang.org/overviews/parallel-collections/conversions.html

关于我的设置

我在Arch Linux上,将OpenJDK 10设置为语言级别9(在Intellij中)和scala-sdk-2.13.0。

导入的库依赖项:
  • scala-library(2.13.0)
  • scala-parallel-collections(2.13.0)
  • 最佳答案

    正如@Thilo在评论中提到的那样,我缺少以下导入,这是从Scala 2.13开始所必需的:
    import scala.collection.parallel.CollectionConverters._

    Source: https://github.com/scala/scala-parallel-collections/issues/22

    关于scala - Scala集合中缺少par方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57287607/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com