I have this code whereby process is having problem compiling with error “Could not find an instance of Applicative”. I know i can import all cats implicits but i wish to learn exactly which instance is missing. Can someone point it out to me?
object Cats extends App {
import cats.data.Validated
import cats.instances.list._
import cats.syntax.traverse._
List(1, 2, 3).traverse(item =>
if (item % 2 == 0) Validated.valid(item)
else Validated.invalid(s"$item is not even")
)
}
The error:
[error] /Users/laiboonhui/learn/cats/hello/src/main/scala/Hello.scala:8:25: Could not find an instance of Applicative for [+A]cats.data.Validated[String,A]
[error] List(1, 2, 3).traverse(item =>
[error] ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
I wonder what instance of Applicative i am missing. Its not list
I highly recommend you just do import cats.implicits._ to get everything, and not import things from cats.instances or cats.syntax. It’s very easy to import insufficient and/or conflicting things.