RxJava2操作符Map

对发送者发送的数据进行操作,然后再发送给接收者

      Observable sender = Observable.create(new ObservableOnSubscribe() {
        @Override
        public void subscribe(@NonNull ObservableEmitter e) throws Exception {

            e.onNext("Hello");

        }
    }).map(new Function() {
        @Override
        public String apply(@NonNull String s) throws Exception {
            
            // 对发送者发送的数据进行操作
            
            return s + "World";
        }
    });
    
    Observer receiver = new Observer() {
        @Override
        public void onSubscribe(@NonNull Disposable d) {
            
        }

        @Override
        public void onNext(@NonNull Object o) {

            Log.i("zzz","o.toString() " + o.toString());
            
            // HelloWorld
        }

        @Override
        public void onError(@NonNull Throwable e) {

        }

        @Override
        public void onComplete() {

        }
    };
    
    sender.subscribe(receiver);

你可能感兴趣的:(RxJava2操作符Map)