本文整理匯總了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;
}