2016-09-06 7 views
0

내가 ValidatedNelHListXorHList을지도하려고으로이 컴파일 오류를 수정하고 오류 도착 방법 : 위의 그것을 해결하는 방법을폴리 기능

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 

코드로 잘못 무엇을 ?

답변

2

수입을 다시 확인할 수 있습니까?

shapeless에서 폴리 대신 자연 전환이 cats 인 것으로 생각됩니다.

toValidation 개체를 정의하기 전에 shapeless.poly._을 가져 오면 해당 오류를 제거해야합니다.

+0

감사합니다. 너는 맞을지 모르지만 나는 또 다른 문제가있다. 나는 그것에 대해 또 다른 질문을 게시 할 것이다. – Michael

+0

이것은 질문입니다, 그건 그렇고 : http://stackoverflow.com/q/39374015/521070 – Michael