Reputation: 552
I have two observables:
Observable <Profile> profileObservable = briteDatabase.createQuery(UserMapper.Table.NAME, sql, String.valueOf(userId)).mapToOneOrDefault(UserMapper.MAPPER, null);
Observable <List<Car>> carObservable = briteDatabase.createQuery(CarMapper.Table.NAME, sql, String.valueOf(userId)).mapToOneOrDefault(CarMapper.MAPPER, null);
public class Profile {
int id;
String name;
ArrayList<Car> car;
...
}
public class Car {
int id;
String brand;
...
}
I need to get list of cars from carObservable and put it to profileObservable (put list of car to Profile), inside method like this:
@Override
public Observable<Profile> getProfile(String userId) {
String sql = String.format("SELECT %s FROM %s WHERE %s=?", TextUtils.join(",", UserMapper.PROJECTION), UserMapper.Table.NAME, UserMapper.Columns.ID);
Observable <Profile> profileObservable = briteDatabase.createQuery(UserMapper.Table.NAME, sql, String.valueOf(userId)).mapToOneOrDefault(UserMapper.MAPPER, null);
Observable <List<Car>> carsObservable = getCars(String userId);
/*
Some important method to concat and return Observable <Profile>. I'm only beginner at RxJava(
*/
}
Upvotes: 0
Views: 278
Reputation: 13471
Did you try the concat operator, I dont know if I understand quite well your use case, but in case you just need to go through the list of car and then profile, just concat one after the other
@Test
public void testContact() {
Observable.concat(Observable.just("Hello"),
Observable.just("reactive"),
Observable.just("world"))
.subscribe(System.out::println);
}
If you want to initiate in the RxJava world take a look here https://github.com/politrons/reactive
Upvotes: 0