【发布时间】:2023-03-19 19:31:01
【问题描述】:
我无法进入 ReactiveX 思维模式,或者我正在使用的代码库写得不好。
假设我有一些 Observable A() 并且我需要来自另一个 Observable B() 的数据以便对来自 A 的数据进行验证,我如何在 RxJava 中完成此操作(更喜欢 RxKotlin 实现)。请注意,A 和 B 都返回对象列表的 Single。
fun B(): Single<List<Bar>> {
...
}
fun A() : Single<List<Foo>> {
Single.just(readRecords()).map { record ->
// val bar = B.getAll()??? This seems like an anti-pattern and I'm not sure if it would necessarily be right to .subscribe()???
if (bar.contains(record)) {
// ... some validation
}
}
}
更新 1:应该强调验证需要多个来源,因此您可以拥有 B、C、D 等。
【问题讨论】: