Scala Parallelism - scala

I am trying to call .par on a Scala vector version 2.13.2 but get the error
Error:(1, 25) object parallel is not a member of package collection
import scala.collection.parallel.CollectionConverters._
I have imported
import scala.collection.parallel.CollectionConverters._
and have also added the dependency
libraryDependencies += "org.scala-lang.modules" %% "scala-parallel-collections" % "0.2.0"
What's wrong?

Related

FunSuite missing even though ScalaTest is imported

I want to start writing simple tests in Scala using ScalaTest.
But for some reason, I can access org.scalatest but not org.scalatest.FunSuite
This is what my build.sbt looks like:
name := "Algorithms"
version := "0.1"
scalaVersion := "2.13.3"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.0"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0" % "test"
I don't understand if it can access scalatest then why are FunSuite,FlatSpec and other styles missing?
Output of running test on sbt shell
[error] <Project Path>\Algorithms\src\test\scala\Course1\Week1\MaxPairProductTest.scala:3:48: type FunSuite is not a member of package org.scalatest
[error] class MaxPairProductTest extends org.scalatest.FunSuite {
[error] ^
ScalaTest 3.2.0 has completed modularisation of the monolith from prior versions
The main change in ScalaTest 3.2.0 is carrying out the modularization
that we prepared for in 3.0.8 and 3.1.0. As a result, many deprecated
names have been removed, because the deprecations would cross module
boundaries.
This means that whilst in 3.1.0 the following definition
import org.scalatest.FunSuite
class ExampleSuite310 extends FunSuite {}
would just raise deprecation notice
The org.scalatest.FunSuite trait has been moved and renamed. Please use org.scalatest.funsuite.AnyFunSuite instead. This can be rewritten automatically with autofix: https://github.com/scalatest/autofix/tree/master/3.1.x", "3.1.0"
in 3.2.0 it has been removed entirely. Hence from 3.2.0 onwards you should define like so
import org.scalatest.funsuite.AnyFunSuite
class ExampleSuite320 extends AnyFunSuite {}
See deprecations expirations for full list of new names.
Note we can still import a single artifact which will pull transitively all the sub-artifacts
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0" % "test"
however now we also have the options of depenending on just the particular sub-artifact
libraryDependencies += "org.scalatest" %% "scalatest-funsuite" % "3.2.0" % "test"

object contrib is not a member of package meta

I am trying to use the isEqual method in ScalaMeta.
import scala.meta.contrib._
q"true".isEqual(q"true")
The import does not work:
object contrib is not a member of package meta
I am using sbt and I have the following in my build.sbt
libraryDependencies += "org.scalameta" %% "scalameta" % "4.0.0"
Where can I find the isEqual method for ScalaMeta? It appears to have been deprecated. I am following this tutorial
To get access to Scalameta Contrib you can add the following dependency:
libraryDependencies += "org.scalameta" %% "contrib" % "4.0.0"
isEqual will be accessible, but q isn't. You can import it from scala.meta._.
The corrected example:
import scala.meta._
import scala.meta.contrib._
q"true".isEqual(q"true")

Intellij Scala classpath not found

I am trying to use json4s but I keep getting the error below when I compile. I thought the library would have the class internally. I am using json4s-ast_2.11-4.0.0-M1.jar, json4s-core_2.12.3.5.3.jar and json4s-jackson_2.9.1-3.0.0.jar.
Error:(64, 25) Symbol 'type org.json4s.JsonAST.JValue' is missing from the classpath.
This symbol is required by 'type org.json4s.JValue'.
Make sure that type JValue is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
A full rebuild may help if 'package.class' was compiled against an incompatible version of org.json4s.JsonAST.
Imports:
import org.json4s.jackson.JsonMethods._
import org.json4s._
build.sbt
scalaVersion := "2.12.4"
libraryDependencies += "org.json4s" %% "json4s-jackson" % "3.0.0"
libraryDependencies += "org.json4s" %% "json4s-ast" % "4.0.0-M1"
libraryDependencies += "org.json4s" %% "json4s-core" % "3.5.3"
You can't use libraries compiled for different versions of scala in other versions. You need to fix the versioning of your JSON4s. Look at:
http://www.scala-sbt.org/0.13/docs/Cross-Build.html#Using+Cross-Built+Libraries

Scala Intellij running test suite

I am doing the Scala course on coursera. I am trying to run the unit tests given in the exercise. However, I am getting the following issues:
Error:(3, 12) object scalatest is not a member of package org
import org.scalatest.FunSuite
^
Error:(6, 12) object junit is not a member of package org
import org.junit.runner.RunWith
^
These appear when I am importing packages into my project:
import org.scalatest.FunSuite
import org.junit.runner.RunWith
I googled this and found the following solution:
Add dependencies like this
libraryDependencies += "com.novocode" % "junit-interface" % "0.8" % "test->default"
I tried adding this code to build.sbt but the errors persist.
ScalaTest is not JUnit. Adding the junit-interface is needed if you want to execute JUnit tests directly with sbt. Obviously you are trying to run ScalaTest tests, though. The additional library dependency you need here is
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.5" % "test"
And then to include JUnit (instead of the junit-sbt-interface), probably this:
libraryDependencies += "junit" % "junit" % "4.12" % "test"

Play framework 2.2 Slick dependency issue

I'm trying to follow this tutorial, but I get stuck as soon as trying to import necessary packages:
import scala.slick.session.Database
import Database.threadLocalSession
import scala.slick.jdbc.{GetResult, StaticQuery => Q}
I'm getting these errors:
object slick is not a member of package scala
not found: object Database
object slick is not a member of package scala
My SBT dependencies:
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"com.typesafe.slick" %% "slick" % "1.0.1",
"com.typesafe.play" %% "play-slick" % "0.5.0.8"
)
What am I missing here?
I'm running Play Framework 2.2.0, Scala 2.10.3
You probably need to run some of these commands in sbt (in this order):
reload
update
eclipse
(obviously substitute eclipse with whatever IDE you are using, or remove it if you are not using an IDE.)