我有对象 List 数据的 List 作为可观察的,其中包括两个子 List , List 。我想分别提取和处理它们。
CustomMapper mapper = new CustomMapper(parentList).
object1List=mapper.getObject1List();
object2List=mapper.getObject2List();
object1Observable.subscribe();
object2Observable.subscribe();
您可以使用share()
Operator获得类似的结果
Observable o = Observable.just(1,2,"one","two",3,"four").share();
o.filter(item -> item instanceof String)
.map((Function<Object, String>) o1 -> o1.toString())
.subscribe(o1 -> System.out.println("String is "+o1));
o.filter(item -> item instanceof Integer)
.map((Function<Object, Integer>) o1 -> ((Integer) o1))
.subscribe(o1 -> System.out.println("Integer is "+o1));
结果是:
String is one
String is two
String is four
Integer is 1
Integer is 2
Integer is 3
更多信息:https : //medium.com/mindorks/how-to-use-rxjava-share-operator-26b08973771a
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句