Skip to content

Instantly share code, notes, and snippets.

@miszmaniac
Created March 16, 2017 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miszmaniac/e4a0258280fe20b80df326f540a02078 to your computer and use it in GitHub Desktop.
Save miszmaniac/e4a0258280fe20b80df326f540a02078 to your computer and use it in GitHub Desktop.
class PublishSubjectMergeUsage {
PublishSubject<List<Car>> cars = PublishSubject.create(...); //Car has some Id
PublishSubject<List<Wheel>> wheels = PublishSubject.create(...); //Wheel have carId which is
public Observable<List<CarWithWheels>> test(Observable<List<Car>> cars, Observable<List<Wheel>> wheels) {
return Observable.combineLatest(
cars.flatMapIterable(c -> c),
wheels.flatMapIterable(w -> w).toMap(Wheel::carId),
(car, wheelsMap) -> new CarWithWheels(car, wheelsMap.get(car.id))
).toList();
}
public subscriptionShouldFireEveryTimeCarsOrWheelsPublishesNewList() {
test(cars, wheels).subscribe(...);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment