【发布时间】:2021-01-10 00:52:35
【问题描述】:
我需要将转换序列处理为一个转换,以便如果我有一些失败的 Future 它应该被忽略(我试图在没有恢复或恢复的情况下这样做,但是 smth 出错了,遇到任何失败时代码都会失败失败)
type Transformation[T] = T => Future[T]
//in - Seq(trans1, trans2, trans3)
in.reduce[Transformation[T]](
(acc, el) =>
acc.andThen[Future[T]](
ft =>
ft.flatMap(el)
.transformWith[T](
t =>
t match {
case Failure(exception) => ft //this line is the most suspicious for me
case Success(value) => Future.successful(value)
}
)
)
)
【问题讨论】:
-
一个变换的输出是下一个变换的输入?
-
一次转换的输出是下一次转换的输入? - 是的,按照我的理解组合它们来制作转换链
-
我想我猜...这是因为我没有处理 acc 初始失败的变体