You have two tables in Room(Rx), let say A & B...
# android
p
You have two tables in Room(Rx), let say A & B. You have to check in table A, if the value returned is valid then check table B and return the result. Else return error to the user. How can this be done using single stream in Rx. Any suggestions?
g
Not sure I understand the question. Could you
tableASingle.flatMap { tableBSingle }
?
p
I think there’s a small step in between,
Copy code
queryTableA.flatMap {
    if (invalid) {
        Single.error(...)
    } else {
        queryTableB
    }
}
👆 2
💯 2
p
If inside the flatMap .. there is no way to avoid this ?
IMG_20200728_124750.jpg
@Guillermo Alcantara
g
avoid what?
👍 1
p
There is an IF check inside the flatMap(). Can we avoid that . That's look ugly to me 😂
g
well you could map the first single and throw an exception if invalid, but that's worse imo
if you are into that, you could create an extension
filterWithError
that does that and can be reused for other streams. Where if predicate is true passes it downstream, otherwise errs.