I am using RxAndroid 2.0.1 with RxJava 2.0.6.
I have two observables: one returns Maybe<MyObject>based on some String (ID). When an additional object is returned, I must call the second, which takes an instance of MyObject, and returns Single<Boolean>if the object satisfies some conditions. Then I can perform some additional operations on the object instance.
My current implementation is as follows:
objectDAO.getById(objectId)
.subscribe(
myObject -> checkCondition(myObject),
throwable -> ,
() ->
);
private void checkCondition(final MyObject myObject) {
otherDAO.checkCondition(myObject)
.subscribe(
isTrue -> {
if (isTrue) {
} else {
}
},
throwable ->
);
}
Now I am wondering how I can simplify my code. My ideas:
Try using zip- I cannot, because the second Observable cannot be signed until the first returns MyObject
filter - , , . , :
objectDAO.getById(objectId)
.filter(myObject ->
otherDAO.checkCondition(myObject).blockingGet()
)
.subscribe(
myObject -> checkCondition(myObject),
throwable -> ,
() ->
);
flatMap - Boolean, . - blockingGet Maybe.empty()
, , "" ( , , )?