Java Code Examples for io.reactivex.Observable.zip()

The following are Jave code examples for showing how to use zip() of the io.reactivex.Observable class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: RxRetroJsoup   File: MainActivity.java   View Source Code Vote up 7 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerview);

    recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
    adapter = new Adapter();
    recyclerView.setAdapter(adapter);

    loadWithRetroJsoup();

    Observable.zip(
            Observable.just(""),
            Observable.just("&"),
            new BiFunction<String, String, String>(){

                @Override
                public String apply(@NonNull String s, @NonNull String s2) throws Exception {
                    return null;
                }
            }
    );
}
 
Example 2
Project: rxjavatraining   File: ObservableTestingTest.java   View Source Code Vote up 6 votes
public Observable<Tuple2<String, Double>> processStock(List<String> stocks, Function<String, String> f) {
    Observable<String> stockNames = Observable.fromIterable(stocks);
    Observable<String> urls = stockNames.map(s -> "https://finance.google.com/finance/historical?output=csv&q=" + s);
    Observable<Optional<String>> optionalObservable = urls
            .subscribeOn(Schedulers.from(executorService))
            .flatMap(s -> {
                try {
                    return Observable.just(Optional.of(f.apply(s)));
                } catch (Throwable t) {
                    return Observable.just(Optional.<String>empty());
                }
            })

            .observeOn(Schedulers.computation())
            .map(opt -> opt.map(doc -> doc.split("\n")[1].split(",")[4]))
            .doOnNext(x -> System.out.println(">>>>" + x));
    return Observable.zip(stockNames, optionalObservable, (name, price) ->
            new Tuple2<>(name, Double.parseDouble(price.orElse("0.0"))));
}
 
Example 3
Project: GitHub   File: ProductBackendApiDecorator.java   View Source Code Vote up 5 votes
/**
 * Get a list with all products from backend
 */
public Observable<List<Product>> getAllProducts() {
  return Observable.zip(getProducts(0), getProducts(1), getProducts(2), getProducts(3),
      (products0, products1, products2, products3) -> {
        List<Product> productList = new ArrayList<Product>();
        productList.addAll(products0);
        productList.addAll(products1);
        productList.addAll(products2);
        productList.addAll(products3);
        return productList;
      });
}
 
Example 4
Project: GitHub   File: ProductBackendApiDecorator.java   View Source Code Vote up 5 votes
/**
 * Get a list with all products from backend
 */
public Observable<List<Product>> getAllProducts() {
  return Observable.zip(getProducts(0), getProducts(1), getProducts(2), getProducts(3),
      (products0, products1, products2, products3) -> {
        List<Product> productList = new ArrayList<Product>();
        productList.addAll(products0);
        productList.addAll(products1);
        productList.addAll(products2);
        productList.addAll(products3);
        return productList;
      });
}
 
Example 5
Project: Rx_java2_soussidev   File: RxBus_java.java   View Source Code Vote up 5 votes
public <CLASS> Observable<CLASS> get(Class<CLASS> theClass) {
    return Observable.zip(
            onEvent(theClass),
            postAsObservable(new AskedEvent(theClass)),
            new BiFunction<CLASS, Object, CLASS>() {
                @Override
                public CLASS apply(@NonNull CLASS neededObject, @NonNull Object _useless) throws Exception {
                    return neededObject;
                }
            });
}
 
Example 6
Project: Dalaran   File: TestGroupTask.java   View Source Code Vote up 5 votes
@Override
public Observable<JSONObject> createFinalFlowObservable() {
    return Observable.zip(getMe, chapter, new BiFunction<JSONObject, JSONArray, JSONObject>() {
        @Override
        public JSONObject apply(@NonNull JSONObject jsonObject, @NonNull JSONArray jsonArray) throws Exception {
            String name = jsonObject.getString("name");
            Log.d("NONO", "TestGroupTask---" + name + ":" + jsonArray.length());
            return new JSONObject();
        }
    });


}