且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用其他 Observable 过滤 RxJava Observable

更新时间:2023-10-19 22:16:34

你可以做的一件事:

objectDAO.getById(objectId)
    .flatMapSingle(myObject -> otherDAO
        .checkCondition(myObject)
        .map(isTrue -> Pair.create(myObject, isTrue))
    )

然后你有一个 Observable> 并且可以按照你想要的方式继续:subscribe 直接并检查 Boolean 在那里,filter 通过布尔值等

Then you have an Observable<Pair<MyObject, Boolean>> and can proceed however you want: subscribe directly and check the Boolean there, filter by the Boolean value, etc.