[英]Convert List[Task[Boolean]] to EitherT[Task, Throwable, Unit]
I have a List[Task[Boolean]]
and I need to turn it into an EitherT[Task, Throwable, Unit]
. 我有一个
List[Task[Boolean]]
,我需要将其变成EitherT[Task, Throwable, Unit]
。
I have one possible solution which is 我有一个可能的解决方案是
EitherT(Task.delay(if (!allAsserts.contains(false)) \/-(()) else -\/(new Exception("BOOM"))))
but I was wondering if it's possible to create the EitherT
without making an explicit call to Task.delay
. 但我想知道是否可以在不显式调用
EitherT
情况下创建Task.delay
。
Perhaps the above code is correct but I was just wondering if there are alternatives. 也许上面的代码是正确的,但是我只是想知道是否还有其他选择。
Perhaps this? 也许这个?
lazy val toDisjuction: List[Boolean] => \/[Throwable, Unit] = list =>
if (list.forall(_ == true)) \/-(()) else -\/(new Exception("BOOM"))
val ltb: List[Task[Boolean]] = ???
EitherT(Task.gatherUnordered(ltb) map toDisjunction)
I think that's what I was looking for ... 我想这就是我想要的...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.