The combine_latest operator allows you to emit items that are composed from the latest value of the items emitted by each source observable. Here is the marble diagram of this operator:
Figure 8.6: The combine_latest operator
This operator can be used as a class method or as a member method:
Observable.combine_latest(self, *args)
Observable.combine_latest(cls, *args)
The args argument contains all the source observables that must be combined. A list can also be provided instead of several arguments. The last argument must be a function that implements the combination logic. This function takes as many input arguments as the source observable provided before.
Here is an example of how to use this operator:
numbers = Observable.from_([1, 2, 3, 4])
characters = Observable.from_(["a", "b", "c"])
characters.combine_latest(numbers, lambda c, n: c + str(n)).subscribe(
on_next = lambda i: print("on_next {}".format(i)),
on_error = lambda e: print("on_error: {}".format(e)),
on_completed = lambda: print("on_completed")
)
This gives the following result: