本文整理汇总了Java中io.reactivex.Observable.combineLatest方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.combineLatest方法的具体用法?Java Observable.combineLatest怎么用?Java Observable.combineLatest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Observable
的用法示例。
在下文中一共展示了Observable.combineLatest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zipMaps
import io.reactivex.Observable; //导入方法依赖的package包/类
public static <T, S> Observable<Map<T, S>> zipMaps(final Map<T, Observable<S>> tasks) {
Objects.requireNonNull(tasks, "tasks is null");
return Observable.combineLatest(
tasks.entrySet()
.stream()
.map(entry -> Observable.combineLatest(
Observable.just(entry.getKey()),
entry.getValue(),
Pair::with))
.collect(ImmutableList.toImmutableList()),
xs -> Arrays.stream(xs)
.map(x -> (Pair<T, S>)x)
.collect(ImmutableMap.toImmutableMap(Pair::getValue0, Pair::getValue1)));
}
示例2: getProductWithShoppingCartInfo
import io.reactivex.Observable; //导入方法依赖的package包/类
private Observable<ProductDetail> getProductWithShoppingCartInfo(int productId) {
List<Observable<?>> observables =
Arrays.asList(backendApi.getProduct(productId), shoppingCart.itemsInShoppingCart());
return Observable.combineLatest(observables, objects -> {
Product product = (Product) objects[0];
List<Product> productsInShoppingCart = (List<Product>) objects[1];
boolean inShoppingCart = false;
for (Product p : productsInShoppingCart) {
if (p.getId() == productId) {
inShoppingCart = true;
break;
}
}
return new ProductDetail(product, inShoppingCart);
});
}
示例3: captchaCommand
import io.reactivex.Observable; //导入方法依赖的package包/类
public RxCommand<String> captchaCommand() {
if (_captchaCommand == null) {
Observable<Boolean> enabled = Observable.combineLatest(
_phoneNumberValid,
countdownCommand().executing(),
(valid, executing) -> valid && !executing);
_captchaCommand = RxCommand.create(enabled, o -> {
String phone = phoneNumber.value().toString();
Timber.i("fetch captcha with %s", phone);
Observable<String> fetchCode = fetchCaptcha(phone);
Observable<String> countdown = Observable.defer(() -> countdownCommand().execute(null).ignoreElements().toObservable()) ;
return Observable.concat(fetchCode, countdown);
});
}
return _captchaCommand;
}
示例4: loginCommand
import io.reactivex.Observable; //导入方法依赖的package包/类
public RxCommand<Boolean> loginCommand() {
if (_loginCommand == null) {
Observable<Boolean> loginInputValid = Observable.combineLatest(
_captchaValid,
_phoneNumberValid,
(captchaValid, phoneValid) -> captchaValid && phoneValid);
_loginCommand = RxCommand.create(loginInputValid, o -> {
String phone = this.phoneNumber.value().toString();
String captcha = this.captcha.value().toString();
return login(phone, captcha);
});
}
return _loginCommand;
}