scala - How to resolve this ambiguity while mapping my Either type? -
suppose i've got 2 types intresult , stringresult:
import cats._ import cats.data._ import cats.implicits._ scala> case class myerror(msg: string) defined class myerror scala> type result[a] = either[nonemptylist[myerror], a] defined type alias result scala> type stringresult = result[string] defined type alias stringresult scala> type intresult = result[int] defined type alias intresult now convert intresult stringresult using map:
scala> val good1: intresult = 10.asright good1: intresult = right(10) scala> good1 map (_.tostring) <console>:26: error: type mismatch; found : good1.type (with underlying type intresult) required: ?{def map: ?} note implicit conversions not applicable because ambiguous: both method catssyntaxeither in trait eithersyntax of type [a, b](eab:either[a,b]) cats.syntax.eitherops[a,b] , method tofunctorops in trait tofunctorops of type [f[_], a](target: f[a])(implicit tc: cats.functor[f])cats.functor.ops[f,a] possible conversion functions good1.type ?{def map: ?} good1 map (_.tostring) how resolve ambiguity ?
the simple approach use projections, do:
good1.right.map(_.tostring) it's not awesome, works. don't know way import functor not conflicting either enrichment (if need both).
of course, import cats.syntax.either._ won't functor.
Comments
Post a Comment