blakelee
08/16/2019, 9:20 PMalexsullivan114
08/18/2019, 2:07 PMswitchIfEmpty
shouldn't fire if the Maybe
completes with a value.blakelee
08/19/2019, 3:25 PMfun getThing(clientId: String): Maybe<SomeResult> {
return dao.getSomeThing(clientId)
.firstOrError()
.flatMapMaybe {
it.firstOrNull { item -> item.end == null }
?.let { Maybe.just(it) } ?: Maybe.empty()
}
.onErrorComplete() // db error, unlikely
.subscribeOn(<http://schedulers.io|schedulers.io>())
}
This calls the above and then has the switch
fun isThing(): Single<Boolean> {
return repo.getThing("some id")
.map { false }
.switchIfEmpty(
if (condition) {
doThing() // Returns Maybe<Boolean>
} else {
Maybe.just(true)
})
.onErrorComplete()
.defaultIfEmpty(true) // Handles db error
.toSingle()
}
The dao above IS returning the item that I need. What happens is it goes to the top function, but also seems to go to the switchIfEmpty at the same time. The top function is getting a Flowable from the db and then getting the first thing. Perhaps it’s the flowable causing issuesblakelee
08/19/2019, 4:12 PMblakelee
08/19/2019, 4:13 PMMaybe.just(item)
.map { false }
.switchIfEmpty(doSomething())
It’s still hitting the switchIfEmptyalexsullivan114
08/19/2019, 5:55 PMdao
look like? Is it a room dao
?blakelee
08/19/2019, 10:56 PMalexsullivan114
08/20/2019, 3:52 PM