The start_with operator

The start_with operator emits items on the output observable before any other item of the source observable. The marble diagram of this operator follows:

Figure 8.5: The start_with operator

The prototype of this operator is the following:

Observable.start_with(self, *args, **kw)

The args parameter contains the items to emit prior to any other one. Optionally, the first argument can be a scheduler. A scheduler can also be provided with the scheduler keyword argument.

The start_with operator can be used this way:

numbers = Observable.from_([1, 2, 3, 4])

numbers.start_with(0).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 gives the following result:

on_next 0
on_next 1
on_next 2
on_next 3
on_next 4
on_completed
..................Content has been hidden....................

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