我有两个不同的文档,它们之间有关系:
class Foo {
String getBarId();
String message();
}
class Bar {
String id();
String description();
}给定Foo的Flowable,我必须将发出的每个项目与Bar的Single合并。以一种非反应性的方式想象一下:
getStreamOfFoo().forEach(f -> {
Bar b = getBarById(f.getBarId());
sendMessage(f.getMessage(), bar.getDescription());
});所以我有返回Flowable<Foo>的getStreamOfFoo方法,返回Single<Bar>的getBarById方法和返回Completable的sendMessage方法。这是我的代码,有一个编译错误,我不知道如何处理:
getFoo().flatMapCompletable(f ->
Single.zip(Single.just(f), getBarById(f.getBarId()),
(foo,bar) -> sendMessage(foo,bar)));谢谢你的帮助。
发布于 2018-04-02 17:58:58
好了,下定决心,我已经接近解决方案了。代码如下:
Completable sendMessage() {
getFoo().map(f ->
Single.zip(
Single.just(f),
getBarById(f.getBarId()),
(foo,bar) -> sendMessage(foo, bar)))
.flatMapCompletable(identity());
}https://stackoverflow.com/questions/49608321
复制相似问题