Useful operators

In this subsection, we will explore operators that transform the elements of a source observable in some way. The most prominent member of this family of operators is the familiar map, which emits the elements of the source observable after applying a function to them. For example, we may use map to calculate the square of a sequence of numbers:

    (Observable.from_iterable(range(4))               .map(lambda x: x**2)               .subscribe(print))    # Output:    # 0    # 1    # 4    # 9

Operators can be represented with marble diagrams that help us better understand how the operator works, especially when taking into account the fact that elements can be emitted over a region of time. In a marble diagram, a data stream (in our case, an observable) is represented ...

Get Python High Performance - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.