I'm new to rxjava. I need to combine two observables that emit objects of different type. Something like Observable<Milk>
and Observable<Cereals>
and get a Observable<CerealsWithMilk>
. I couldn't find any operator for something like this. What would be the rx way of doing something like this? Note that Milk
and Cereals
are async.
相关问题
- Load script async?
- C# An asynchronous operation cannot be started at
- In a UIViewControllerRepresentable, how can I pass
- aio_write on linux with rtkaio is sometimes long
- await work in chrome console without async wrapper
相关文章
- RxJava takeUntil with emmision of last item?
- With a Promise, why do browsers return a reject tw
- Asynchronous SHA256 Hashing
- Does aiohttp have ORM?
- Error handling for zipped observables
- How does RxJava Observable “Iteration” work?
- Can each Iteration of a for loop/for_each be done
- How does robospice manage activity lifecycle?
If you want to merge observables of different type you need to use
Observable.zip
:result
will be an observable generating the application of(a, b) -> a + b
too1
's ando2
's items. Resulting in an observable yielding"a1", "b2", "c3"
.You can use any function. For example
It's hard to say without knowing exactly what you need, but possibly zip() or combineLatest().
zip
will take bothObservable<Milk>
andObservable<Cereals>
and let you combine them intoCerealsWithMilk
via a provided function. This emits a newCerealsWithMilk
each time you get get both aMilk
and aCereals
.combineLatest
is similar tozip
except it will emit a newCerealsWithMilk
even if just a newMilk
or just a newCereals
is emitted.