August 2018
Intermediate to advanced
248 pages
5h 51m
English
Let's see a similar example (in the rx_example3.py file) where we react to the Observable (the stream of quotes created using the same get_quotes() function), using a chain of flat_map(), filter(), and map() operations.
The main difference from the previous example is that we schedule the streaming of items so that a new item is emitted every five seconds (the interval), using the Observable.interval() function. Furthermore, we use the flat_map() method to map each emission to an Observable (Observable.from_(zen_quotes) for example) and merge their emissions together into a single Observable.
The main part of the code is as follows:
Observable.interval(5000) \ .flat_map(lambda seq: Observable.from_(zen_quotes)) \ .flat_map(lambda ...