Nabih Nebbache
Nabih Nebbache

Reputation: 60

methode map in class cats.data.Nested not recognized

I have a problem when folowing the scala cats library tutorial, the map method applied to the Nested class is highlighted with red, and the compiler doesn't recognize it.

here is my main class code :

import cats._
import cats.data._
import cats.implicits._
import cats.syntax.functor._
import cats.Functor
import cats.instances.list._
import cats.instances.option._

object Main extends App{
  val list = List(Some(1), Some(2), None, Some(4))


  val nested: Nested[List, Option, Int] = Nested(list)
  //here is the problem
  nested.map(_ + 1)   
}

here is my build.sbt file

name := "dailySBT3"

version := "0.1"

scalaVersion := "2.12.5"

scalacOptions += "-Ypartial-unification"

libraryDependencies += "org.typelevel" %% "cats-core" % "1.1.0"

Upvotes: 2

Views: 419

Answers (1)

Luka Jacobowitz
Luka Jacobowitz

Reputation: 23502

The problem is you are importing the instances and syntax twice. The following works for me with no problems:

import cats._
import cats.data._
import cats.implicits._

object Main extends App{
  val list = List(Some(1), Some(2), None, Some(4))


  val nested: Nested[List, Option, Int] = Nested(list)

  nested.map(_ + 1)   
}

You could also do the same thing as above but get rid of the cats.implicits._ import instead.

When in doubt, check out the cats import guide.

Upvotes: 3

Related Questions