나는 서적 Advanced scala with cats
에서 간단한 운동을하고 있습니다.고양이와 스칼라 - Cartesian + Validated
Cartesian
과 Validated
을 사용하고 싶습니다.
/* this doesnt work*/
type Result[A] = Validated[List[String], A]
Cartesian[ValidatedString].product(
f(somevariable)//returns Result[String],
g(somevariable)//returns Result[Int],
).map(User.tupled) // creates an user from the returned string, int
임 완전히 우둔
/*
this works
*/
type ValidatedString = Validated[ Vector[String], String]
Cartesian[ValidatedString].product(
"a".valid[Vector[String]],
"b".valid[Vector[String]]
)
. 어떤 힌트? 임 점점 :
could not find implicit value for parameter instance: cats.Cartesian[Result] Cartesian[Result].product( ^
첫 번째 예제에서는'ValidationString'을'Vector [] '로 정의하고 두 번째 예제에서는'List []'로 정의합니다. 이것이 진정한 차이입니까? –
'ValidatedString'은 유형 생성자가 아니기 때문에 부차적 인 부분이지만 처음 코드 스 니펫은 실제로 작동하지 않습니다. 이 질문은 향후 독자가 코드를 올바르게 설명하도록하는 데 더 유용 할 것입니다. –