I have two different documents with a relation:
class Foo {
String getBarId();
String message();
}
class Bar {
String id();
String description();
}
Given an Flowable
of Foo
I have to merge every item emitted with a Single
of Bar
. Imagine in non Reactive way the following:
getStreamOfFoo().forEach(f -> {
Bar b = getBarById(f.getBarId());
sendMessage(f.getMessage(), bar.getDescription());
});
So I have the method getStreamOfFoo
that returns a Flowable<Foo>
, the getBarById
the returns a Single<Bar>
and the sendMessage
that returns a Completable
.
This is my code, there is a compiling error that I don't know how to manage:
getFoo().flatMapCompletable(f ->
Single.zip(Single.just(f), getBarById(f.getBarId()),
(foo,bar) -> sendMessage(foo,bar)));
Thanks for the help.
答案 0 :(得分:0)
好的,解决了,我接近解决方案。这是代码:
Completable sendMessage() {
getFoo().map(f ->
Single.zip(
Single.just(f),
getBarById(f.getBarId()),
(foo,bar) -> sendMessage(foo, bar)))
.flatMapCompletable(identity());
}