Created
March 16, 2017 22:23
-
-
Save miszmaniac/e4a0258280fe20b80df326f540a02078 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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