I have following code that works well.
Observable.from(...)
.map { // List<Object>
if (My_Condition_is_true) {
//...
}
val newList = getNewListIfConditionIsOkay(it)
newList.map { item -> toSomethingElse(item) }
}
.subscribeBy(myErrorFun) {
//...
}
I feel map
operator does not looks cool but I have no idea how to fix it. This is what is in my mind.
Observable.from(...)
.doOnNext {// List<Object>
if (My_Condition_is_true) {
//...
return getNewListIfConditionIsOkay(it)
}
return it
.map { // List<Object>
it.map { item -> toSomethingElse(item) }
}
.subscribeBy(myErrorFun) {
//...
}
My Observable returns only a list. What is your recommendation?
map
is fine. SavedoOnNext
for side effect tasks,doOnNext
actually doesn't return any value, so I don't think your code would even work here.