I am trying to follow a simple example from the scala with cats ebook. here is my code
import cats.Semigroupal
import cats.instances.option._
import cats.syntax.apply._
import cats.implicits._
case class Name(fName: String, lName: String)
(Some("foo"), Some("bar")).mapN(Name.apply)
I get the error
cmd4.sc:1: could not find implicit value for parameter functor: cats.Functor[Some]
val res4 = (Some("foo"), Some("bar")).mapN(Name.apply)
I also tried importing
cats.functor._
cats.syntax.functor._
The problem is that Functor is invariant in its type argument, so you need to make the Scala compiler treat the type of the tuple as (Option[String], Option[String])
instead of (Some[String], Some[String])
. You can do this using
("foo".some, "bar".some).mapN(Name.apply)