The take_last operator returns only the n last items emitted by the source observable. The following figure shows the marble diagram of this operator:
Figure 9.7: The take_last operator
The prototype of this operator is the following:
take_last(self, count)
Here, count is the number of items to keep from the source observable.
Here is an example of this operator:
numbers = Observable.from_([1, 2, 3, 4, 5, 6])
numbers.take_last(2).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: