Hi guys, I don’t know what I doing wrong but my ne...
# rx
f
Hi guys, I don’t know what I doing wrong but my next is never call inside the subscribe
Copy code
rx.Observable.merge(
        events.map{
               eventbus.rxSend(....).toObservalbe()
       }
}.subscribe(next,error)
e
flatMap
instead of
map
f
thanks 😉 why should I user flatMap for that?
and I remove the merge?
I can’t use flatMap because eventbus.rxSend(....).toObservalbe() is not a Iterable
Maybe that :
Copy code
Observable.from(validEvents).flatMap { notifyNextNode(node, it, messageBody, send) }
e
Why a merge in the first place?
f
I have a list of observable, I need to return only one
to subscribe it in another place
e
I think there is a extension in RxKotlin that help convert
List<Observable>
into
Observable
f
thanks
e
Not sure though
f
I’ll look
😉
Does it seem good to you?
Copy code
validEvents.toObservable().flatMap { notifyNextNode(node, it, messageBody, send) }
e
Copy code
events.merge().subscribe { notifyNextNode(...) }
Make use of Kotlin's extension function to make you code more readable and meaningful
f
👍 thanks
ok it returns now a list of subscription
e
How come a list of subs instead of a single sub?
f
ok, it was my fault, I have now a Subscription. What are the best practices, do a subscribe inside each function and return subscription or return observable from all function? And do subscibe only on the call chain on the top?
ok now thanks @edwardwongtl
e
I would return a Observable instead of Subscription, unless you need to execute it now.
f
yes I read a book about rxjava, it’s more clear now. I should have started with that