The zip_list operator

The zip_list operator behaves like the zip operator, but its output items are lists instead of a combination of the source items. Each list item contains all items emitted by the source observables. The following figure shows the marble diagram of the zip_list operator:

Figure 9.16: The zip_list operator

Its prototype is the following:

Observable.zip_list(cls, *args)

Here, all the observables to be combined are provided as arguments.

Here is an example of the zip_list operator:

numbers = Observable.from_([1, 2, 3, 4])
characters = Observable.from_(['a', 'b', 'c', 'd' ,'e'])

Observable.zip_list(characters, numbers).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 example gives the following result:

on_next ['a', 1]
on_next ['b', 2]
on_next ['c', 3]
on_next ['d', 4]
on_completed

Each item of the two source observables is combined pairwise, and returned in lists.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.27.74