「开源框架」RxJava(3)变换操作符「map/flatmap」

「开源框架」RxJava(3)变换操作符「map/flatmap」_第1张图片
RxJava

RxJava 变换操作符 map / flatmap

Map

拦截与接收被观察者发送的事件,按照需求改变事件,再发送给观察者「观察者接收到的事件是改变后的事件」

Observable.create(new ObservableOnSubscribe() {
            @Override
            public void subscribe(ObservableEmitter emitter) throws Exception {
                emitter.onNext(1);
                emitter.onNext(2);
                emitter.onNext(3);
            }
        }).map(new Function() {
            @Override
            public String apply(Integer integer) throws Exception {
                return "This is result " + integer;
            }
        }).subscribe(new Consumer() {
            @Override
            public void accept(String s) throws Exception {
                Log.d(TAG, s); //接收的String为改变后的String
            }
        });

//Print 
 D/TAG: This is result 1 
 D/TAG: This is result 2 
 D/TAG: This is result 3

参考文章:
https://juejin.im/post/5848dd3eac502e00691385c5

你可能感兴趣的:(「开源框架」RxJava(3)变换操作符「map/flatmap」)