These are chat archives for ReactiveX/RxJava

26th
Oct 2017
Min Hiew
@mhiew
Oct 26 2017 17:57

Hi everyone. How does one convert an Observable of one type to another type:
Observable<T> to Observable<R>

Are we supposed to use the to operator or perhaps flatMap?

When I try using flatmap it complains about observable cannot be applied to anonymous function<Observable<T>, Observable<R>>

Mark Elston
@melston
Oct 26 2017 19:19
@mhiew , I may have misunderstood your question but what is the issue using Map? If you provide a function T -> R doesn't this do what you want?
David Stocking
@dmstocking
Oct 26 2017 19:20
Are you asking how to take an Observable<T> and make it an Observable<R>? Just call map. If you want to map from an Observable<T> to Observable<R> via multiple Observable<R> then you need flatmap.
map (T -> R) -> R
flatmap (T -> Observable<R>) -> R (I hope I wrote that right)
Mark Elston
@melston
Oct 26 2017 19:23
@dmstocking, that looks right.
Min Hiew
@mhiew
Oct 26 2017 19:23

Hi, I believe the issue was due to my misunderstanding of flatmap. I thought it was going to pass in `Observable<T>.

(Observable<T> -> Observable<R>)

But as @dmstocking mentioned it should be:
(T -> Observable<R>)

Changing that fixed things for me.
Thank you