Книга: Learning Concurrency in Python
Назад: Combining observables
Дальше: Output

Zip() example

In this example, we'll use the .zip() operator in order to combine both the letters Observable as well as the intervals Observable into one Observable. Then, we will use the .subscribe() operator in order to subscribe a very simple Observer to this newly combined Observable object:

from rx import Observable


list1 = [23, 38, 43, 23]

letters = Observable.from_(list1).to_blocking()
intervals = Observable.interval(1000)

def main():
Observable \
.zip(letters, intervals, lambda x, y: (x*y, y))
\
.subscribe(lambda t: print(t))

if __name__ == '__main__':
main()
input("Press any key to quit\n")
Назад: Combining observables
Дальше: Output