When using RxJava2 in Java I have the advantage of map() filtering emitted null values automatically. However with nullable types in Kotlin I end up doing something like this:
val loadConferencesSingle = service.getConferences()
.map { it.conferences ?: listOf<Conference>() }
The call service.getConferences() in this case is a Single emitting a ConferecesResponse which looks like
data class ConferencesResponse(val conferences: List<Conference?>? = null)
So in case the complete emitted list of conferences is null, I ended up using the Elvis operator to emit an empty list instead. Emitting a null in map is not possible.
Has anybody a clue, how to handle nullable types better in RxJava with Kotlin? I already like this solution and its terseness, but I've got the feeling that there are even better ways to handle this.