bsky
bsky

Reputation: 20222

Cats can not resolve symbol |@|

I have the following code, which I got from here: http://underscore.io/blog/posts/2015/06/10/an-introduction-to-cats.html.

import cats.data.Xor
import cats.data.{Validated, Xor}
import cats.syntax.apply._ // For |@| syntax
import cats.std.list._
val v1: ValidatedR = valid(1)
val v2: ValidatedR = invalid(List("Accumulates this"))
val v3: ValidatedR = invalid(List("And this"))
(v1 |@| v2 |@| v3) map { _ + _ + _ }

However, I'm getting:

Cannot resolve symbol |@|

My build.sbt:

val snapshots = "Sonatype Snapshots"  at "https://oss.sonatype.org/content/repositories/snapshots"

val algebraVersion = "0.2.0-SNAPSHOT"
val catsVersion    = "0.1.0-SNAPSHOT"

val algebra    = "org.spire-math" %% "algebra" % algebraVersion
val algebraStd = "org.spire-math" %% "algebra-std" % algebraVersion

val cats       = "org.spire-math" %% "cats-core" % catsVersion
val catsStd    = "org.spire-math" %% "cats-std" % catsVersion

scalaVersion := "2.11.6"

libraryDependencies ++=
  Seq(
    algebra, algebraStd,
    cats, catsStd
  )

resolvers += snapshots

Is there anything else that I should be importing or using?

Upvotes: 1

Views: 1140

Answers (1)

Peter Neyens
Peter Neyens

Reputation: 9820

The example is a little dated. A few things have changed since then :

  • |@| is now provided by the Cartesian type class compared to the Apply type class before.
  • The imports for types like Option, List, ... from the Scala standard library have been renamed from cats.std.xxx to cats.instances.xxx.
  • The latest version of Cats doesn't have the Xor data type any more, but uses the scala.util.Either data type instead.

Like I mentioned in my comment, it is easier to use the "uber" import cats.implicits._.

For some similar (and up to date) examples you could take a look at the Cats documentation of Validated and Either.

Upvotes: 6

Related Questions