假设我有:
JAXBContext
我想将它们组合在一起并得到一个val x1: Either[String, Int] = Right(1)
val x2: Either[String, Float] = Left("Nope")
val x3: Either[String, Double] = Left("Not Today")
。为此,我目前正在执行以下操作:
Either[NonEmptyList[String], (Int, Float, Double)]
完成这项工作,但有点乏味。是否可以通过仅调用import cats.syntax.all._
(
x1.toValidatedNel,
x2.toValidatedNel,
x3.toValidatedNel
).tupled
.toEither
一次来做到这一点?像这样:
toValidatedNel
这样的(x1, x2, x3)
.fooMap(_.toValidatedNel)
.tupled
.toEither
是否存在于猫的某个地方?还是我们需要fooMap
?
答案 0 :(得分:3)
使用Shapeless,它是
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 0.0.0.0:3001 fd 4
uWSGI http bound on 127.0.0.1:9090 fd 5
uwsgi socket 0 bound to TCP address 127.0.0.1:42183 (port auto-assigned) fd 3
Python version: 3.7.2 (default, Jan 11 2019, 21:31:15) [GCC 5.4.0 20160609]