RxJava 替代 map() 运算符来保存发出的项目

RxJava alternative for map() operator to save emitted items

我使用 Retrofit 与 REST 进行交互 API 并且 RxJava 操作我收到的数据。

在下面的代码片段中,我进行了一个 API 调用,并使用 map 运算符保存我收到的数据,然后再继续对流进行其他操作。

retrofitApi.registerDevice(mDevice)
           .map(new Func1<Device, Device>() {
               @Override
               public Device call(Device device) {
                  // The only purpose of the map() operator 
                  // is to save the received device.
                  magicBox.saveDeviceId(device.getId());
                  return device;
               }
           })
           .otherOperations()...

我的问题是:是否有更好的操作员来完成这项工作?我觉得我误用了 map 运算符。

看起来 doOnEach() 是您要找的东西,但我自己还没有尝试过。

I did some research and, based on Dan Lew's blogpost and 之后,正确答案似乎是 doOnNext.