Tengansui Tengansui - 2 months ago 17
Scala Question

Scalaz cannot resolve symbol |+|, unused import statement

I'm trying to use the Scalaz operator |+| as suggested in this question

Best way to merge two maps and sum the values of same key?

import scalaz._

val map1 = Map("a" -> 1,"b" -> 2, "c" -> 5)
val map2 = Map("a" -> 3,"b" -> 4)
val map3 = map1 |+| map2


Intellij says |+| cannot resolve symbol and import.scalaz._ is unused.
The SBT seems to be working just fine and the import statement looks valid but here it is just in case.

"org.scalaz" %% "scalaz-core" % "7.2.6"


Whats happening?

Answer

import both scalaz._ and Scalaz._

import scalaz._
import Scalaz._

notice S in Scalazis Uppercase letter in the second import

Scala REPL

scala> import scalaz._
import scalaz._

scala> import Scalaz._
import Scalaz._

scala> val map1 = Map("a" -> 1,"b" -> 2, "c" -> 5)
map1: Map[String, Int] = Map("a" -> 1, "b" -> 2, "c" -> 5)

scala> val map2 = Map("a" -> 3,"b" -> 4)
map2: Map[String, Int] = Map("a" -> 3, "b" -> 4)

scala> val map3 = map1 |+| map2
map3: Map[String, Int] = Map("a" -> 4, "b" -> 6, "c" -> 5)