添加到@maxost的答案,在这里你可以避免最后一个toCompletable()
和toObservable()
:
createThing(panel)
.flatMap(new Function<Channel, ObservableSource<? extends Item>>() {
@Override public ObservableSource<? extends Item> apply(Channel channel) throws Exception {
return createOrUpdateItem(channel).toObservable();
}
},
new BiFunction<Channel, Item, Completable>() {
@Override public Completable apply(Channel channel, Item item) throws Exception {
return linkItemToChannel(item.name, channel.uid);
}
}
)
.ignoreElements() // converts to Completable
拉姆达德:
createThing(panel)
.flatMap(channel -> createOrUpdateItem(channel).toObservable(),
(channel, item) -> linkItemToChannel(item.name, channel.uid))
.ignoreElements() // converts to Completable