【发布时间】:2018-12-16 12:43:31
【问题描述】:
我有一个处理Source 并返回的方法。我正在尝试修改它,但似乎无法返回相同的内容:
原创
def originalMethod[as: AS, mat: MAT, ec: EC](checkType: String)
: Flow[ByteString, MyValidation[MyClass], NotUsed]{
collectStuff
.map { ts =>
val errors = MyEngine.checkAll(ts.code)
(ts, errors)
}
.map { x =>
x._2
.leftMap(xs => {
addInformation(x._1, xs.toList)
})
.toEither
}
}
我正在使用另一个源进行修改并将结果传递给原始源,但返回相同的东西:
def calculate[T: AS: MAT](source: Source[T, NotUsed]): Future[Seq[T]] =
{
source.runWith(Sink.seq)
}
def modifiedMethod[as: AS, mat: MAT, ec: EC](checkType: String, mySource: Source[LoanApplicationRegister, NotUsed])
: Flow[ByteString, MyValidation[MyClass], NotUsed]{
for {
calc <- calculate(mySource)
orig <- collectStuff
.map { ts =>
val errors = MyEngine.checkAll(ts.code, calc)
(ts, errors)
}
.map { x =>
x._2
.leftMap(xs => {
addInformation(x._1, xs.toList)
})
.toEither
}
}
yield {
orig
}
}
但我收到编译错误Expression of type Future[Nothing] doesn't conform to existing type Flow[ByteString, MyValidation[MyClass]
我怎样才能在我的modifiedMethod 中返回Flow[ByteString, MyValidation[MyClass],就像originalMethod 一样
【问题讨论】:
标签: scala akka akka-stream