简体   繁体   English

将列表[任务[布尔]]转换为EitherT [任务,可投掷,单位]

[英]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.

相关问题 将列表[任务[列表[A]]]转换为任务[列表[A]] - Convert List[Task[List[A]]] to Task[List[A]] 将列表[任务(用户名,描述)]转换为Map [用户名,设置[任务]] - Convert a List[Task(username, description)] into Map[username,Set[Task]] 是否可以将输出为Either [Throwable,Unit]的同步函数调用转换为Future [Either [Throwable,Unit]]? - Is it possible to convert synchronous function call with output of Either[Throwable, Unit] to Future[Either[Throwable, Unit]]? Task[List[List[A]]] 到 Task[A] 如果列表有元素 - Task[List[List[A]]] to Task[A] if list has elements Cats EitherT 转换为 Future[结果] - Cats EitherT convert to Future[Result] 使用猫列出[EitherT [Future,A,B]]到EitherT [Future,A,List [B]] - List[EitherT[Future, A, B]] to EitherT[Future, A, List[B]] with cats List [EitherT [Future,String,CustomObj]] => EitherT [Future,String,List [CustomObj]] - List[EitherT[Future, String, CustomObj]] => EitherT[Future, String, List[CustomObj]] 将EitherT [Future,A,Future [B]]转换为EitherT [Future,A,B] - Convert EitherT[Future, A, Future[B]] to EitherT[Future, A, B] 列出 sbt `Task` 标签 - List sbt `Task` tags ZIO 在 Future[Either[MyException, A]] 中传播自定义异常系列,没有仅可抛出的任务 - ZIO Propagate custom exception family within Future[Either[MyException, A]], without Task which is Throwable only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM