Combine latest¶
See also
- zip
- Official ReactiveX documentation: CombineLatest
- RxPY marbles: |operator-marbles-combine_latest|
- RxPY marbles: |operator-marbles-with_latest_from|
-
classmethod
Observable.
combine_latest
(*args)¶ Merges the specified observable sequences into one observable sequence by using the selector function whenever any of the observable sequences produces an element.
- 1 - obs = Observable.combine_latest(obs1, obs2, obs3,
- lambda o1, o2, o3: o1 + o2 + o3)
- 2 - obs = Observable.combine_latest([obs1, obs2, obs3],
- lambda o1, o2, o3: o1 + o2 + o3)
Returns an observable sequence containing the result of combining elements of the sources using the specified result selector function.
>>> from rx.testing import marbles >>> xs = rx.Observable.from_marbles('1-2-3-4-|') >>> ys = rx.Observable.from_marbles('-a-b-c-d-e|') >>> source = xs.combine_latest(ys, lambda x, y: x+y) >>> subscription = source.subscribe( ... lambda value: print("Next:", value), ... lambda error: print("Error:", error), ... lambda: print("Complete!")) Next: 2a Next: 3a Next: 3b Next: 4b Next: 4c Next: 4d Next: 4e Complete!
-
classmethod
Observable.
with_latest_from
(*args)¶ Merges the specified observable sequences into one observable sequence by using the selector function only when the first observable sequence produces an element. The observables can be passed either as seperate arguments or as a list.
- Excamples::
- obs = Observable.with_latest_from(obs1, obs2, obs3,
- lambda o1, o2, o3: o1 + o2 + o3)
- obs = Observable.with_latest_from([obs1, obs2, obs3],
- lambda o1, o2, o3: o1 + o2 + o3)
Returns an observable sequence containing the result of combining elements of the sources using the specified result selector function.
>>> from rx.testing import marbles >>> xs = rx.Observable.from_marbles('1--2-3-4-|') >>> ys = rx.Observable.from_marbles('-a-b-c-d-e|') >>> source = xs.combine_latest(ys, lambda x, y: x+y) >>> subscription = source.subscribe( ... lambda value: print("Next:", value), ... lambda error: print("Error:", error), ... lambda: print("Complete!")) Next: 2a Next: 3b Next: 4c Complete!