So I have following Disposable which doesn't work. I am using Room to get all rows from a table as a list, map each of them to something and create a list and then it doesn't continue from there.
storedSuggestionDao
.getSuggestionsOrderByType() //Flowable
.doOnNext(storedSuggestions -> Timber.e("storedSuggestions: " + storedSuggestions)) //this work
.flatMapIterable(storedSuggestions -> storedSuggestions)
.map(Selection::create) ))
.doOnNext(selection -> Timber.e("Selection: " + selection)) // works
.toList()
.toObservable() // nothing works after this...
.doOnNext(selections -> Timber.d("selections: " + selections))
.map(SuggestionUiModel::create)
.doOnNext(suggestionUiModel -> Timber.d("suggestionUiModel: " + suggestionUiModel))
.subscribe();
These types of data sources from 3rd parties are usually infinite sources but toList()
requires a finite source. I guess you wanted to process that collection of storedSuggestions
and keep it together. You can achieve this via an inner transformation:
storedSuggestionDao
.getSuggestionsOrderByType() //Flowable
.doOnNext(storedSuggestions -> Timber.e("storedSuggestions: " + storedSuggestions)) //this work
// -------------------------------------
.flatMapSingle(storedSuggestions ->
Flowable.fromIterable(storedSuggestions)
.map(Selection::create)
.doOnNext(selection -> Timber.e("Selection: " + selection))
.toList()
)
// -------------------------------------
.doOnNext(selections -> Timber.d("selections: " + selections))
.map(SuggestionUiModel::create)
.doOnNext(suggestionUiModel -> Timber.d("suggestionUiModel: " + suggestionUiModel))
.subscribe();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With