當前位置: 首頁>>代碼示例>>Java>>正文


Java Observable.combineLatest方法代碼示例

本文整理匯總了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)));
    }
 
開發者ID:LoopPerfect,項目名稱:buckaroo,代碼行數:17,代碼來源:MoreObservables.java

示例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);
  });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:DetailsInteractor.java

示例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;
}
 
開發者ID:listenzz,項目名稱:RxCommand,代碼行數:18,代碼來源:LoginViewModel.java

示例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;
}
 
開發者ID:listenzz,項目名稱:RxCommand,代碼行數:16,代碼來源:LoginViewModel.java


注:本文中的io.reactivex.Observable.combineLatest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。