0

I am trying to map an HList of Xor to an HList of ValidatedNel and got an error:

scala> type Result[A] = Xor[String, A]    
defined type alias Result

scala> type Validation[A] = ValidatedNel[String, A]
defined type alias Validation

scala> val r0 = Xor.right(0)
r0: cats.data.Xor[Nothing,Int] = Right(0)

scala> val r1 = Xor.left("xxx")
r1: cats.data.Xor[String,Nothing] = Left(xxx)

scala> import shapeless._
import shapeless._

scala> val rs = r0 :: r1 :: HNil
rs: shapeless.::[cats.data.Xor[Nothing,Int],shapeless.::[cats.data.Xor[String,Nothing],shapeless.HNil]] = Right(0) :: Left(xxx) :: HNil

scala> object toValidation extends (Result ~> Validation) { def apply[T](r: Result[T]): Validation[T] = r.toValidatedNel }
defined object toValidation

scala> rs map toValidation
<console>:41: error: type mismatch;
 found   : toValidation.type
 required: shapeless.Poly
              rs map toValidation

What's wrong with the code above and how to fix it ?

Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

2

Could you double check your imports?

I suspect that ~> references the natural transformation from cats instead of Poly from shapeless.

Importing shapeless.poly._ before defining the toValidation object should get rid of that error.

Denis Rosca
  • 3,409
  • 19
  • 38
  • Thanks. You are probably right but I have another problem now. I will post another question about it. – Michael Sep 07 '16 at 15:04