如何使用RxJava CombineLatest运算符与9个以上可观察对象 [英] How to use RxJava combineLatest operator with more than 9 observables

查看:86
本文介绍了如何使用RxJava CombineLatest运算符与9个以上可观察对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RxJava,我想使用运算符 combineLatest 组合12种不同的可观察对象.

I'm using RxJava and I want to combine 12 different observables using the operator combineLatest.

我看到了一个函数原型,该原型带有一个可观察值列表和一个 FuncN 的实现,但是我不确定该怎么做,我在实现 call时遇到了麻烦方法.

I saw a function prototype that takes a list of observables and an implementation of FuncN but I'm not sure how to do this, I'm having trouble implementing the call method.

有人可以给我举个例子吗?

Can someone show me an example?

推荐答案

有一个

There is a combineLatest that takes a List of observables. Here's an example on how to use it:

List<Observable<?>> list = Arrays.asList(Observable.just(1), Observable.just("2"));
Observable.combineLatest(list, new FuncN<String>() {
    @Override
    public String call(Object... args) {
        String concat = "";
        for (Object value : args) {
            if (value instanceof Integer) {
                concat += (Integer) value;
            } else if (value instanceof String) {
                concat += (String) value;
            }
        }
        return concat;
    }
});

这篇关于如何使用RxJava CombineLatest运算符与9个以上可观察对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆