Skip to Content
Mastering Python Design Patterns - Second Edition
book

Mastering Python Design Patterns - Second Edition

by Kamon Ayeva, Sakis Kasampalis
August 2018
Intermediate to advanced
248 pages
5h 51m
English
Packt Publishing
Content preview from Mastering Python Design Patterns - Second Edition

A third example

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Python Design Patterns - Second Edition - Second Edition

Learning Python Design Patterns - Second Edition - Second Edition

Chetan Giridhar, Gennadiy Zlobin

Publisher Resources

ISBN: 9781788837484Supplemental Content