Observable base class.
Represents a push-style collection, which you can pipe
into
operators
.
Creates an observable sequence object from the specified subscription function.
subscribe (Optional
[Callable
[[ObserverBase
[TypeVar
(_T_out
, covariant=True)], Optional
[SchedulerBase
]], DisposableBase
]]) – [Optional] Subscription function
Subscribe an observer to the observable sequence.
You may subscribe using an observer or callbacks, not both; if the first
argument is an instance of Observer
or if
it has a (callable) attribute named on_next
, then any callback
arguments will be ignored.
Examples
>>> source.subscribe()
>>> source.subscribe(observer)
>>> source.subscribe(observer, scheduler=scheduler)
>>> source.subscribe(on_next)
>>> source.subscribe(on_next, on_error)
>>> source.subscribe(on_next, on_error, on_completed)
>>> source.subscribe(on_next, on_error, on_completed, scheduler=scheduler)
observer – [Optional] The object that is to receive notifications.
on_error (Optional
[Callable
[[Exception
], None
]]) – [Optional] Action to invoke upon exceptional termination
of the observable sequence.
on_completed (Optional
[Callable
[[], None
]]) – [Optional] Action to invoke upon graceful termination
of the observable sequence.
on_next (Union
[ObserverBase
[TypeVar
(_T_out
, covariant=True)], Callable
[[TypeVar
(_T_out
, covariant=True)], None
], None
]) – [Optional] Action to invoke for each element in the
observable sequence.
scheduler (Optional
[SchedulerBase
]) – [Optional] The default scheduler to use for this
subscription.
DisposableBase
Disposable object representing an observer’s subscription to the observable sequence.
Compose multiple operators left to right.
Composes zero or more operators into a functional composition. The operators are composed from left to right. A composition of zero operators gives back the original source.
Examples
>>> source.pipe() == source
>>> source.pipe(f) == f(source)
>>> source.pipe(g, f) == f(g(source))
>>> source.pipe(h, g, f) == f(g(h(source)))
operators (Callable
[[Any
], Any
]) – Sequence of operators.
Any
The composed observable.
Run source synchronously.
Subscribes to the observable source. Then blocks and waits for the observable source to either complete or error. Returns the last value emitted, or throws exception if any error occurred.
Examples
>>> result = run(source)
SequenceContainsNoElementsError – if observable completes (on_completed) without any values being emitted.
Exception – raises exception if any error (on_error) occurred.
Any
The last element emitted from the observable.
Awaits the given observable.
Generator
[Any
, None
, TypeVar
(_T_out
, covariant=True)]
The last item of the observable sequence.
Pythonic version of concat
.
Example
>>> zs = xs + ys
other (Observable
[TypeVar
(_T_out
, covariant=True)]) – The second observable sequence in the concatenation.
Observable
[TypeVar
(_T_out
, covariant=True)]
Concatenated observable sequence.
Pythonic use of concat
.
Example
>>> xs += ys
other (Observable
[TypeVar
(_T_out
, covariant=True)]) – The second observable sequence in the concatenation.
Observable[_T_out]
Concatenated observable sequence.
Pythonic version of slice
.
Slices the given observable using Python slice notation. The arguments to slice are start, stop and step given within brackets [] and separated by the colons :.
It is basically a wrapper around the operators
skip
,
skip_last
,
take
,
take_last
and
filter
.
The following diagram helps you remember how slices works with streams. Positive numbers are relative to the start of the events, while negative numbers are relative to the end (close) of the stream.
r---e---a---c---t---i---v---e---!
0 1 2 3 4 5 6 7 8
-8 -7 -6 -5 -4 -3 -2 -1 0
Examples
>>> result = source[1:10]
>>> result = source[1:-2]
>>> result = source[1:-1:2]
key (Union
[slice
, int
]) – Slice object
Observable
[TypeVar
(_T_out
, covariant=True)]
Sliced observable sequence.
TypeError – If key is not of type int
or slice