【问题标题】:RxJava alternative for map() operator to save emitted itemsmap() 运算符的 RxJava 替代方法来保存发出的项目
【发布时间】:2015-05-10 09:17:56
【问题描述】:

我使用 Retrofit 与 REST API 进行交互,而 RxJava 会处理我收到的数据。

在下面的代码 sn-p 中,我进行 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 运算符。

【问题讨论】:

    标签: android retrofit rx-java


    【解决方案1】:

    Egor's answer 之后,我做了一些研究,基于Dan Lew's blogpostthis question,正确答案似乎是 doOnNext.

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-10
        • 2020-06-05
        • 1970-01-01
        • 2023-04-06
        • 2019-04-28
        • 2019-02-20
        • 1970-01-01
        相关资源
        最近更新 更多