2

I am trying to create an instance of Either using asRight in REPL:

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

scala> val x = "xxx".asRight
<console>:20: error: value asRight is not a member of String
       val x = "xxx".asRight
                 ^

scala> import cats.syntax.either._
import cats.syntax.either._

scala> val x = "xxx".asRight
<console>:23: error: value asRight is not a member of String
       val x = "xxx".asRight
                 ^

What's wrong with the code above ? Is it possible to use asRight in REPL ?

Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

7

EitherIdOps which includes asRight and asLeft ops was first introduced in cats 0.9.0 (the latest release at the time of writing). You are most likely using an earlier version.

scala> import cats._, implicits._
import cats._
import implicits._

scala> "xxx".asRight
res0: Either[Nothing,String] = Right(xxx)

scala> "xxx".asRight[Int]
res1: Either[Int,String] = Right(xxx)
Michael Zajac
  • 55,144
  • 7
  • 113
  • 138