【发布时间】:2017-02-08 01:46:06
【问题描述】:
我正在自己做一个来自Advanced scala with cats 的简单练习。
我想将Cartesian 与Validated 一起使用。
/*
this works
*/
type ValidatedString = Validated[ Vector[String], String]
Cartesian[ValidatedString].product(
"a".valid[Vector[String]],
"b".valid[Vector[String]]
)
/* 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
我完全一无所知。有什么提示吗? 我得到:
could not find implicit value for parameter instance: cats.Cartesian[Result]
Cartesian[Result].product(
^
【问题讨论】:
-
在第一个示例中,您根据
Vector[]定义ValidatedString,而在第二个示例中,您根据List[]定义它。这是真正的区别吗? -
这是一个小问题,但你的第一个代码 sn-p 不实际上工作,因为
ValidatedString不是类型构造函数。这将使这个问题对未来的读者更有用,以确保您的代码描述正确。
标签: scala scala-cats