7

I tried to convert a sequential list to a parallel one in Intellij, but I get the error

Cannot resolve symbol par

on the .par method call:

import scala.collection.parallel.immutable._
...
val parList = List(1,2,3).par

According to https://docs.scala-lang.org/overviews/parallel-collections/overview.html, one must simply

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.

What makes me wonder is that I did not find any par method in the current immutable list api of scala: https://www.scala-lang.org/api/current/scala/collection/immutable/List.html

But there's even a dedicated scala doc-page for sequential to parallel conversion which uses the par method: https://docs.scala-lang.org/overviews/parallel-collections/conversions.html

About my setup

I'm on Arch Linux with OpenJDK 10 set at language level 9 (in Intellij) and scala-sdk-2.13.0.

Imported library dependencies:

  • scala-library (2.13.0)
  • scala-parallel-collections (2.13.0)
Mario Galic
  • 47,285
  • 6
  • 56
  • 98
langfingaz
  • 356
  • 3
  • 11
  • 2
    Did you `import scala.collection.parallel.CollectionConverters._` ? – Thilo Jul 31 '19 at 10:14
  • I didn't. And to do so solves my problem! Thanks :) As you do not get import recommendations for Scala (as opposed to Java programming) in Intellij, do you have any ideas how I could have discovered that solution? I'm still new to Scala. – langfingaz Jul 31 '19 at 11:08
  • Possible duplicate of [Missing import scala.collection.parallel in Scala 2.13](https://stackoverflow.com/questions/56542568/missing-import-scala-collection-parallel-in-scala-2-13) – Luis Miguel Mejía Suárez Jul 31 '19 at 12:00

2 Answers2

11

As @Thilo mentioned in a comment, I was missing the following import which is necessary since Scala 2.13:

import scala.collection.parallel.CollectionConverters._

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

langfingaz
  • 356
  • 3
  • 11
4

Apart from the import:

import scala.collection.parallel.CollectionConverters._ 

you also need to add dependency in pom.xml of your maven project:

<dependency>
        <groupId>org.scala-lang.modules</groupId>
        <artifactId>scala-parallel-collections_2.13</artifactId>
        <version>0.2.0</version>
</dependency>
hackeryang
  • 59
  • 5