Operators

rx.operators.all(predicate)

Determines whether all elements of an observable sequence satisfy a condition.

all

Example

>>> op = all(lambda value: value.length > 3)
Parameters

predicate (Callable[[~T1], bool]) – A function to test each element for a condition.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.

rx.operators.amb(right_source)

Propagates the observable sequence that reacts first.

amb

Example

>>> op = amb(ys)
Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that surfaces any of the given sequences, whichever reacted first.

rx.operators.as_observable()

Hides the identity of an observable sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns and observable sequence that hides the identity of the source sequence.

rx.operators.average(key_mapper=None)

The average operator.

Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.

average

Examples

>>> op = average()
>>> op = average(lambda x: x.value)
Parameters

key_mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] A transform function to apply to each element.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing a single element with the average of the sequence of values.

rx.operators.buffer(boundaries)

Projects each element of an observable sequence into zero or more buffers.

buffer

Examples

>>> res = buffer(rx.interval(1.0))
Parameters

boundaries (Observable) – Observable sequence whose elements denote the creation and completion of buffers.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns an observable sequence of buffers.

rx.operators.buffer_when(closing_mapper)

Projects each element of an observable sequence into zero or more buffers.

buffer_when

Examples

>>> res = buffer_when(lambda: rx.timer(0.5))
Parameters

closing_mapper (Callable[[], Observable]) – A function invoked to define the closing of each produced buffer. A buffer is started when the previous one is closed, resulting in non-overlapping buffers. The buffer is closed when one item is emitted or when the observable completes.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns an observable sequence of windows.

rx.operators.buffer_toggle(openings, closing_mapper)

Projects each element of an observable sequence into zero or more buffers.

buffer_toggle

>>> res = buffer_toggle(rx.interval(0.5), lambda i: rx.timer(i))
Parameters
  • openings (Observable) – Observable sequence whose elements denote the creation of buffers.

  • closing_mapper (Callable[[Any], Observable]) – A function invoked to define the closing of each produced buffer. Value from openings Observable that initiated the associated buffer is provided as argument to the function. The buffer is closed when one item is emitted or when the observable completes.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns an observable sequence of windows.

rx.operators.buffer_with_count(count, skip=None)

Projects each element of an observable sequence into zero or more buffers which are produced based on element count information.

buffer_with_count

Examples

>>> res = buffer_with_count(10)(xs)
>>> res = buffer_with_count(10, 1)(xs)
Parameters
  • count (int) – Length of each buffer.

  • skip (Optional[int]) – [Optional] Number of elements to skip between creation of consecutive buffers. If not provided, defaults to the count.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns an observable sequence of buffers.

rx.operators.buffer_with_time(timespan, timeshift=None, scheduler=None)

Projects each element of an observable sequence into zero or more buffers which are produced based on timing information.

buffer_with_time

Examples

>>> # non-overlapping segments of 1 second
>>> res = buffer_with_time(1.0)
>>> # segments of 1 second with time shift 0.5 seconds
>>> res = buffer_with_time(1.0, 0.5)
Parameters
  • timespan (Union[timedelta, float]) – Length of each buffer (specified as a float denoting seconds or an instance of timedelta).

  • timeshift (Union[timedelta, float, None]) – [Optional] Interval between creation of consecutive buffers (specified as a float denoting seconds or an instance of timedelta). If not specified, the timeshift will be the same as the timespan argument, resulting in non-overlapping adjacent buffers.

  • scheduler (Optional[Scheduler]) – [Optional] Scheduler to run the timer on. If not specified, the timeout scheduler is used

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence of buffers.

rx.operators.buffer_with_time_or_count(timespan, count, scheduler=None)

Projects each element of an observable sequence into a buffer that is completed when either it’s full or a given amount of time has elapsed.

buffer_with_time_or_count

Examples

>>> # 5s or 50 items in an array
>>> res = source.buffer_with_time_or_count(5.0, 50)
>>> # 5s or 50 items in an array
>>> res = source.buffer_with_time_or_count(5.0, 50, Scheduler.timeout)
Parameters
  • timespan – Maximum time length of a buffer.

  • count – Maximum element count of a buffer.

  • scheduler – [Optional] Scheduler to run buffering timers on. If not specified, the timeout scheduler is used.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence of buffers.

rx.operators.catch(handler)

Continues an observable sequence that is terminated by an exception with the next observable sequence.

catch

Examples

>>> op = catch(ys)
>>> op = catch(lambda ex: ys(ex))
Parameters

handler (Union[Observable, Callable[[Exception, Observable], Observable]]) – Second observable sequence used to produce results when an error occurred in the first sequence, or an exception handler function that returns an observable sequence given the error and source observable that occurred in the first sequence.

Return type

Callable[[Observable], Observable]

Returns

A function taking an observable source and returns an observable sequence containing the first sequence’s elements, followed by the elements of the handler sequence in case an exception occurred.

rx.operators.combine_latest(*others)

Merges the specified observable sequences into one observable sequence by creating a tuple whenever any of the observable sequences produces an element.

combine_latest

Examples

>>> obs = combine_latest(other)
>>> obs = combine_latest(obs1, obs2, obs3)
Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable sources and returns an observable sequence containing the result of combining elements of the sources into a tuple.

rx.operators.concat(*sources)

Concatenates all the observable sequences.

concat

Examples

>>> op = concat(xs, ys, zs)
Return type

Callable[[Observable], Observable]

Returns

An operator function that takes one or more observable sources and returns an observable sequence that contains the elements of each given sequence, in sequential order.

rx.operators.contains(value, comparer=None)

Determines whether an observable sequence contains a specified element with an optional equality comparer.

contains

Examples

>>> op = contains(42)
>>> op = contains({ "value": 42 }, lambda x, y: x["value"] == y["value"])
Parameters
  • value (Any) – The value to locate in the source sequence.

  • comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] An equality comparer to compare elements.

Return type

Callable[[Observable], Observable]

Returns

A function that takes a source observable that returns an observable sequence containing a single element determining whether the source sequence contains an element that has the specified value.

rx.operators.count(predicate=None)

Returns an observable sequence containing a value that represents how many elements in the specified observable sequence satisfy a condition if provided, else the count of items.

count

Examples

>>> op = count()
>>> op = count(lambda x: x > 3)
Parameters

predicate (Optional[Callable[[~T1], bool]]) – A function to test each element for a condition.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing a single element with a number that represents how many elements in the input sequence satisfy the condition in the predicate function if provided, else the count of items in the sequence.

rx.operators.debounce(duetime, scheduler=None)

Ignores values from an observable sequence which are followed by another value before duetime.

debounce

Example

>>> res = debounce(5.0) # 5 seconds
Parameters
  • duetime (Union[timedelta, float]) – Duration of the throttle period for each value (specified as a float denoting seconds or an instance of timedelta).

  • scheduler (Optional[Scheduler]) – Scheduler to debounce values on.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes the source observable and returns the debounced observable sequence.

rx.operators.throttle_with_timeout(duetime, scheduler=None)

Ignores values from an observable sequence which are followed by another value before duetime.

debounce

Example

>>> res = debounce(5.0) # 5 seconds
Parameters
  • duetime (Union[timedelta, float]) – Duration of the throttle period for each value (specified as a float denoting seconds or an instance of timedelta).

  • scheduler (Optional[Scheduler]) – Scheduler to debounce values on.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes the source observable and returns the debounced observable sequence.

rx.operators.default_if_empty(default_value=None)

Returns the elements of the specified sequence or the specified value in a singleton sequence if the sequence is empty.

default_if_empty

Examples

>>> res = obs = default_if_empty()
>>> obs = default_if_empty(False)
Parameters

default_value (Optional[Any]) – The value to return if the sequence is empty. If not provided, this defaults to None.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the specified default value if the source is empty otherwise, the elements of the source.

rx.operators.delay_subscription(duetime, scheduler=None)

Time shifts the observable sequence by delaying the subscription.

delay_subscription

Example

>>> res = delay_subscription(5.0) # 5s
Parameters
  • duetime (Union[datetime, timedelta, float]) – Absolute or relative time to perform the subscription

  • at.

  • scheduler (Optional[Scheduler]) – Scheduler to delay subscription on.

Return type

Callable[[Observable], Observable]

Returns

A function that take a source observable and returns a time-shifted observable sequence.

rx.operators.delay_with_mapper(subscription_delay=None, delay_duration_mapper=None)

Time shifts the observable sequence based on a subscription delay and a delay mapper function for each element.

delay_with_mapper

Examples

>>> # with mapper only
>>> res = source.delay_with_mapper(lambda x: Scheduler.timer(5.0))
>>> # with delay and mapper
>>> res = source.delay_with_mapper(rx.timer(2.0), lambda x: rx.timer(x))
Parameters
  • subscription_delay – [Optional] Sequence indicating the delay for the subscription to the source.

  • delay_duration_mapper – [Optional] Selector function to retrieve a sequence indicating the delay for each given element.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns a time-shifted observable sequence.

rx.operators.dematerialize()

Dematerialize operator.

Dematerializes the explicit notification values of an observable sequence as implicit notifications.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence exhibiting the behavior corresponding to the source sequence’s notification values.

rx.operators.delay(duetime, scheduler=None)

The delay operator.

delay

Time shifts the observable sequence by duetime. The relative time intervals between the values are preserved.

Examples

>>> res = delay(timedelta(seconds=10))
>>> res = delay(5.0)
Parameters
  • duetime (Union[timedelta, float]) – Relative time, specified as a float denoting seconds or an instance of timedelta, by which to shift the observable sequence.

  • scheduler (Optional[Scheduler]) – [Optional] Scheduler to run the delay timers on. If not specified, the timeout scheduler is used.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes the source observable and returns a time-shifted sequence.

rx.operators.distinct(key_mapper=None, comparer=None)

Returns an observable sequence that contains only distinct elements according to the key_mapper and the comparer. Usage of this operator should be considered carefully due to the maintenance of an internal lookup structure which can grow large.

distinct

Examples

>>> res = obs = xs.distinct()
>>> obs = xs.distinct(lambda x: x.id)
>>> obs = xs.distinct(lambda x: x.id, lambda a,b: a == b)
Parameters
  • key_mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] A function to compute the comparison key for each element.

  • comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] Used to compare items in the collection.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence only containing the distinct elements, based on a computed key value, from the source sequence.

rx.operators.distinct_until_changed(key_mapper=None, comparer=None)

Returns an observable sequence that contains only distinct contiguous elements according to the key_mapper and the comparer.

distinct_until_changed

Examples

>>> op = distinct_until_changed();
>>> op = distinct_until_changed(lambda x: x.id)
>>> op = distinct_until_changed(lambda x: x.id, lambda x, y: x == y)
Parameters
  • key_mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] A function to compute the comparison key for each element. If not provided, it projects the value.

  • comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] Equality comparer for computed key values. If not provided, defaults to an equality comparer function.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.

rx.operators.do(observer)

Invokes an action for each element in the observable sequence and invokes an action on graceful or exceptional termination of the observable sequence. This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.

do

>>> do(observer)
Parameters

observer (Observer[-T_in]) – Observer

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes the source observable and returns the source sequence with the side-effecting behavior applied.

rx.operators.do_action(on_next=None, on_error=None, on_completed=None)

Invokes an action for each element in the observable sequence and invokes an action on graceful or exceptional termination of the observable sequence. This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline.

do_action

Examples

>>> do_action(send)
>>> do_action(on_next, on_error)
>>> do_action(on_next, on_error, on_completed)
Parameters
  • on_next (Optional[Callable[[Any], None]]) – [Optional] Action to invoke for each element in the observable sequence.

  • on_error (Optional[Callable[[Exception], None]]) – [Optional] Action to invoke on exceptional termination of the observable sequence.

  • on_completed (Optional[Callable[[], None]]) – [Optional] Action to invoke on graceful termination of the observable sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes the source observable an returns the source sequence with the side-effecting behavior applied.

rx.operators.do_while(condition)

Repeats source as long as condition holds emulating a do while loop.

do_while

Parameters

condition (Callable[[~T1], bool]) – The condition which determines if the source will be repeated.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence which is repeated as long as the condition holds.

rx.operators.element_at(index)

Returns the element at a specified index in a sequence.

element_at

Example

>>> res = source.element_at(5)
Parameters

index (int) – The zero-based index of the element to retrieve.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that produces the element at the specified position in the source sequence.

rx.operators.element_at_or_default(index, default_value=None)

Returns the element at a specified index in a sequence or a default value if the index is out of range.

element_at_or_default

Example

>>> res = source.element_at_or_default(5)
>>> res = source.element_at_or_default(5, 0)
Parameters
  • index (int) – The zero-based index of the element to retrieve.

  • default_value (Optional[Any]) – [Optional] The default value if the index is outside the bounds of the source sequence.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns an observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.

rx.operators.exclusive()

Performs a exclusive waiting for the first to finish before subscribing to another observable. Observables that come in between subscriptions will be dropped on the floor.

exclusive

Return type

Callable[[Observable], Observable]

Returns

An exclusive observable with only the results that happen when subscribed.

rx.operators.expand(mapper)

Expands an observable sequence by recursively invoking mapper.

Parameters

mapper (Callable[[~T1], ~T2]) – Mapper function to invoke for each produced element, resulting in another sequence to which the mapper will be invoked recursively again.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence containing all the elements produced

by the recursive expansion.

rx.operators.filter(predicate)

Filters the elements of an observable sequence based on a predicate by incorporating the element’s index.

filter

Example

>>> op = filter(lambda value: value < 10)
Parameters

predicate (Callable[[~T1], bool]) – A function to test each source element for a condition.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains elements from the input sequence that satisfy the condition.

rx.operators.filter_indexed(predicate_indexed=None)

Filters the elements of an observable sequence based on a predicate by incorporating the element’s index.

filter_indexed

Example

>>> op = filter_indexed(lambda value, index: (value + index) < 10)
Parameters

predicate – A function to test each source element for a condition; the second parameter of the function represents the index of the source element.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains elements from the input sequence that satisfy the condition.

rx.operators.finally_action(action)

Invokes a specified action after the source observable sequence terminates gracefully or exceptionally.

finally_action

Example

>>> res = finally_action(lambda: print('sequence ended')
Parameters

action (Callable) – Action to invoke after the source observable sequence terminates.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the action-invoking termination behavior applied.

rx.operators.find(predicate)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.

find

Parameters

predicate (Callable[[~T1], bool]) – The predicate that defines the conditions of the element to search for.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the first element that matches the conditions defined by the specified predicate, if found otherwise, None.

rx.operators.find_index(predicate)

Searches for an element that matches the conditions defined by the specified predicate, and returns an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.

find_index

Parameters

predicate (Callable[[~T1], bool]) – The predicate that defines the conditions of the element to search for.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, -1.

rx.operators.first(predicate=None)

Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.

first

Examples

>>> res = res = first()
>>> res = res = first(lambda x: x > 3)
Parameters

predicate (Optional[Callable[[~T1], bool]]) – [Optional] A predicate function to evaluate for elements in the source sequence.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns an observable sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.

rx.operators.first_or_default(predicate=None, default_value=None)

Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.

first_or_default

Examples

>>> res = first_or_default()
>>> res = first_or_default(lambda x: x > 3)
>>> res = first_or_default(lambda x: x > 3, 0)
>>> res = first_or_default(None, 0)
Parameters
  • predicate (Optional[Callable[[~T1], bool]]) – [optional] A predicate function to evaluate for elements in the source sequence.

  • default_value (Optional[Any]) – [Optional] The default value if no such element exists. If not specified, defaults to None.

Return type

Callable[[Observable], Observable]

Returns

A function that takes an observable source and returns an observable sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.

rx.operators.flat_map(mapper=None)

The flat_map operator.

flat_map

One of the Following: Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.

Example

>>> flat_map(lambda x: Observable.range(0, x))

Or: Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.

Example

>>> flat_map(Observable.of(1, 2, 3))
Parameters

mapper (Optional[Callable[[~T1], ~T2]]) – A transform function to apply to each element or an observable sequence to project each element from the source sequence onto.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes a source observable and returns an observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.

rx.operators.flat_map_indexed(mapper_indexed=None)

The flat_map_indexed operator.

One of the Following: Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.

flat_map_indexed

Example

>>> source.flat_map_indexed(lambda x, i: Observable.range(0, x))

Or: Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.

Example

>>> source.flat_map_indexed(Observable.of(1, 2, 3))
Parameters

mapper_indexed (Optional[Callable[[~T1, int], ~T2]]) – [Optional] A transform function to apply to each element or an observable sequence to project each element from the source sequence onto.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.

rx.operators.flat_map_latest(mapper)

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element’s index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

Parameters

mapper (Callable[[~T1], ~T2]) – A transform function to apply to each source element. The second parameter of the function represents the index of the source element.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence whose elements are the result of invoking the transform function on each element of source producing an observable of Observable sequences and that at any point in time produces the elements of the most recent inner observable sequence that has been received.

rx.operators.group_by(key_mapper, element_mapper=None)

Groups the elements of an observable sequence according to a specified key mapper function and comparer and selects the resulting elements by using a specified function.

group_by

Examples

>>> group_by(lambda x: x.id)
>>> group_by(lambda x: x.id, lambda x: x.name)
Keyword Arguments
  • key_mapper – A function to extract the key for each element.

  • element_mapper – [Optional] A function to map each source element to an element in an observable group.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns a sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.

rx.operators.group_by_until(key_mapper, element_mapper, duration_mapper)

Groups the elements of an observable sequence according to a specified key mapper function. A duration mapper function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.

group_by_until

Examples

>>> group_by_until(lambda x: x.id, None, lambda : rx.never())
>>> group_by_until(lambda x: x.id, lambda x: x.name, lambda grp: rx.never())
Parameters
  • key_mapper (Callable[[~T1], ~T2]) – A function to extract the key for each element.

  • element_mapper (Optional[Callable[[~T1], ~T2]]) – A function to map each source element to an element in an observable group.

  • duration_mapper (Callable[[GroupedObservable], Observable]) – A function to signal the expiration of a group.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns a sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value. If a group’s lifetime expires, a new group with the same key value can be created once an element with such a key value is encountered.

rx.operators.group_join(right, left_duration_mapper, right_duration_mapper)

Correlates the elements of two sequences based on overlapping durations, and groups the results.

group_join

Parameters
  • right (Observable) – The right observable sequence to join elements for.

  • left_duration_mapper (Callable[[Any], Observable]) – A function to select the duration (expressed as an observable sequence) of each element of the left observable sequence, used to determine overlap.

  • right_duration_mapper (Callable[[Any], Observable]) – A function to select the duration (expressed as an observable sequence) of each element of the right observable sequence, used to determine overlap.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains elements combined into a tuple from source elements that have an overlapping duration.

rx.operators.ignore_elements()

Ignores all elements in an observable sequence leaving only the termination messages.

ignore_elements

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an empty observable sequence that signals termination, successful or exceptional, of the source sequence.

rx.operators.is_empty()

Determines whether an observable sequence is empty.

is_empty

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing a single element determining whether the source sequence is empty.

rx.operators.join(right, left_duration_mapper, right_duration_mapper)

Correlates the elements of two sequences based on overlapping durations.

join

Parameters
  • right (Observable) – The right observable sequence to join elements for.

  • left_duration_mapper (Callable[[Any], Observable]) – A function to select the duration (expressed as an observable sequence) of each element of the left observable sequence, used to determine overlap.

  • right_duration_mapper (Callable[[Any], Observable]) – A function to select the duration (expressed as an observable sequence) of each element of the right observable sequence, used to determine overlap.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains elements combined into a tuple from source elements that have an overlapping duration.

rx.operators.last(predicate=None)

The last operator.

Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.

last

Examples

>>> op = last()
>>> op = last(lambda x: x > 3)
Parameters

predicate (Optional[Callable[[~T1], bool]]) – [Optional] A predicate function to evaluate for elements in the source sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the last element in the observable sequence that satisfies the condition in the predicate.

rx.operators.last_or_default(predicate=None, default_value=None)

The last_or_default operator.

Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.

last

Examples

>>> res = last_or_default()
>>> res = last_or_default(lambda x: x > 3)
>>> res = last_or_default(lambda x: x > 3, 0)
>>> res = last_or_default(None, 0)
Parameters
  • predicate (Optional[Callable[[~T1], bool]]) – [Optional] A predicate function to evaluate for elements in the source sequence.

  • default_value (Optional[Any]) – [Optional] The default value if no such element exists. If not specified, defaults to None.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.

rx.operators.map(mapper=None)

The map operator.

Project each element of an observable sequence into a new form.

map

Example

>>> map(lambda value: value * 10)
Parameters

mapper (Optional[Callable[[~T1], ~T2]]) – A transform function to apply to each source element.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns an observable sequence whose elements are the result of invoking the transform function on each element of the source.

rx.operators.map_indexed(mapper_indexed=None)

Project each element of an observable sequence into a new form by incorporating the element’s index.

map_indexed

Example

>>> ret = map_indexed(lambda value, index: value * value + index)
Parameters

mapper_indexed (Optional[Callable[[~T1, int], ~T2]]) – A transform function to apply to each source element. The second parameter of the function represents the index of the source element.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns an observable sequence whose elements are the result of invoking the transform function on each element of the source.

rx.operators.materialize()

Materializes the implicit notifications of an observable sequence as explicit notification values.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the materialized notification values from the source sequence.

rx.operators.max(comparer=None)

Returns the maximum value in an observable sequence according to the specified comparer.

max

Examples

>>> op = max()
>>> op = max(lambda x, y:  x.value - y.value)
Parameters

comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] Comparer used to compare elements.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns an observable sequence containing a single element with the maximum element in the source sequence.

rx.operators.max_by(key_mapper, comparer=None)

The max_by operator.

Returns the elements in an observable sequence with the maximum key value according to the specified comparer.

max_by

Examples

>>> res = max_by(lambda x: x.value)
>>> res = max_by(lambda x: x.value, lambda x, y: x - y)
Parameters
  • key_mapper (Callable[[~T1], ~T2]) – Key mapper function.

  • comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] Comparer used to compare key values.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and return an observable sequence containing a list of zero or more elements that have a maximum key value.

rx.operators.merge(*sources, max_concurrent=None)

Merges an observable sequence of observable sequences into an observable sequence, limiting the number of concurrent subscriptions to inner sequences. Or merges two observable sequences into a single observable sequence.

merge

Examples

>>> op = merge(max_concurrent=1)
>>> op = merge(other_source)
Parameters

max_concurrent (Optional[int]) – [Optional] Maximum number of inner observable sequences being subscribed to concurrently or the second observable sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns the observable sequence that merges the elements of the inner sequences.

rx.operators.merge_all()

The merge_all operator.

Merges an observable sequence of observable sequences into an observable sequence.

merge_all

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns the observable sequence that merges the elements of the inner sequences.

rx.operators.min(comparer=None)

The min operator.

Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.

min

Examples

>>> res = source.min()
>>> res = source.min(lambda x, y: x.value - y.value)
Parameters

comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] Comparer used to compare elements.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing a single element with the minimum element in the source sequence.

rx.operators.min_by(key_mapper, comparer=None)

The min_by operator.

Returns the elements in an observable sequence with the minimum key value according to the specified comparer.

min_by

Examples

>>> res = min_by(lambda x: x.value)
>>> res = min_by(lambda x: x.value, lambda x, y: x - y)
Parameters
  • key_mapper (Callable[[~T1], ~T2]) – Key mapper function.

  • comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] Comparer used to compare key values.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and reuturns an observable sequence containing a list of zero or more elements that have a minimum key value.

rx.operators.multicast(subject=None, subject_factory=None, mapper=None)

Multicasts the source sequence notifications through an instantiated subject into all uses of the sequence within a mapper function. Each subscription to the resulting sequence causes a separate multicast invocation, exposing the sequence resulting from the mapper function’s invocation. For specializations with fixed subject types, see Publish, PublishLast, and Replay.

Examples

>>> res = multicast(observable)
>>> res = multicast(subject_factory=lambda scheduler: Subject(), mapper=lambda x: x)
Parameters
  • subject_factory (Optional[Callable[[Optional[Scheduler]], Subject[-T_in, +T_out]]]) – Factory function to create an intermediate subject through which the source sequence’s elements will be multicast to the mapper function.

  • subject (Optional[Subject[-T_in, +T_out]]) – Subject to push source elements into.

  • mapper (Optional[Callable[[ConnectableObservable], Observable]]) – [Optional] Mapper function which can use the multicasted source sequence subject to the policies enforced by the created subject. Specified only if subject_factory” is a factory function.

Return type

Callable[[Observable], Union[Observable, ConnectableObservable]]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a mapper function.

rx.operators.observe_on(scheduler)

Wraps the source sequence in order to run its observer callbacks on the specified scheduler.

Parameters

scheduler (Scheduler) – Scheduler to notify observers on.

This only invokes observer callbacks on a scheduler. In case the subscription and/or unsubscription actions have side-effects that require to be run on a scheduler, use subscribe_on.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns the source sequence whose observations happen on the specified scheduler.

rx.operators.on_error_resume_next(second)

Continues an observable sequence that is terminated normally or by an exception with the next observable sequence.

on_error

Keyword Arguments

second – Second observable sequence used to produce results after the first sequence terminates.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence that concatenates the first and second sequence, even if the first sequence terminates exceptionally.

rx.operators.pairwise()

The pairwise operator.

Returns a new observable that triggers on the second and subsequent triggerings of the input observable. The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair. The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable that triggers on successive pairs of observations from the input observable as an array.

rx.operators.partition(predicate)

Returns two observables which partition the observations of the source by the given function. The first will trigger observations for those values for which the predicate returns true. The second will trigger observations for those values where the predicate returns false. The predicate is executed once for each subscribed observer. Both also propagate all error observations arising from the source and each completes when the source completes.

partition

Parameters
  • predicate (Callable[[~T1], bool]) – The function to determine which output Observable

  • trigger a particular observation. (will) –

Return type

Callable[[Observable], List[Observable]]

Returns

An operator function that takes an observable source and returns a list of observables. The first triggers when the predicate returns True, and the second triggers when the predicate returns False.

rx.operators.partition_indexed(predicate_indexed)

The indexed partition operator.

Returns two observables which partition the observations of the source by the given function. The first will trigger observations for those values for which the predicate returns true. The second will trigger observations for those values where the predicate returns false. The predicate is executed once for each subscribed observer. Both also propagate all error observations arising from the source and each completes when the source completes.

partition_indexed

Parameters
  • predicate – The function to determine which output Observable

  • trigger a particular observation. (will) –

Return type

Callable[[Observable], List[Observable]]

Returns

A list of observables. The first triggers when the predicate returns True, and the second triggers when the predicate returns False.

rx.operators.pluck(key)

Retrieves the value of a specified key using dict-like access (as in element[key]) from all elements in the Observable sequence.

To pluck an attribute of each element, use pluck_attr.

Parameters

key (Any) – The key to pluck.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns a new observable sequence of key values.

rx.operators.pluck_attr(prop)

Retrieves the value of a specified property (using getattr) from all elements in the Observable sequence.

To pluck values using dict-like access (as in element[key]) on each element, use pluck.

Parameters

property – The property to pluck.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns a new observable sequence of property values.

rx.operators.publish(mapper=None)

The publish operator.

Returns an observable sequence that is the result of invoking the mapper on a connectable observable sequence that shares a single subscription to the underlying sequence. This operator is a specialization of Multicast using a regular Subject.

Example

>>> res = publish()
>>> res = publish(lambda x: x)
Parameters

mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all notifications of the source from the time of the subscription on.

Return type

Callable[[Observable], ConnectableObservable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a mapper function.

rx.operators.publish_value(initial_value, mapper=None)

Returns an observable sequence that is the result of invoking the mapper on a connectable observable sequence that shares a single subscription to the underlying sequence and starts with initial_value.

This operator is a specialization of Multicast using a BehaviorSubject.

Examples

>>> res = source.publish_value(42)
>>> res = source.publish_value(42, lambda x: x.map(lambda y: y * y))
Parameters
  • initial_value (Any) – Initial value received by observers upon subscription.

  • mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] Optional mapper function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive immediately receive the initial value, followed by all notifications of the source from the time of the subscription on.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a mapper function.

rx.operators.reduce(accumulator, seed=<class 'rx.internal.utils.NotSet'>)

The reduce operator.

Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.

For aggregation behavior with incremental intermediate results, see scan.

reduce

Examples

>>> res = reduce(lambda acc, x: acc + x)
>>> res = reduce(lambda acc, x: acc + x, 0)
Parameters
  • accumulator (Callable[[~TState, ~T1], ~TState]) – An accumulator function to be invoked on each element.

  • seed (Any) – Optional initial accumulator value.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns an observable sequence containing a single element with the final accumulator value.

rx.operators.ref_count()

Returns an observable sequence that stays connected to the source as long as there is at least one subscription to the observable sequence.

Return type

Callable[[ConnectableObservable], Observable]

rx.operators.repeat(repeat_count=None)

Repeats the observable sequence a specified number of times. If the repeat count is not specified, the sequence repeats indefinitely.

repeat

Examples

>>> repeated = repeat()
>>> repeated = repeat(42)
Parameters
  • repeat_count (Optional[int]) – Number of times to repeat the sequence. If not

  • repeats the sequence indefinitely. (provided,) –

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable sources and returna an observable sequence producing the elements of the given sequence repeatedly.

rx.operators.replay(mapper=None, buffer_size=None, window=None, scheduler=None)

The replay operator.

Returns an observable sequence that is the result of invoking the mapper on a connectable observable sequence that shares a single subscription to the underlying sequence replaying notifications subject to a maximum time length for the replay buffer.

This operator is a specialization of Multicast using a ReplaySubject.

Examples

>>> res = replay(buffer_size=3)
>>> res = replay(buffer_size=3, window=0.5)
>>> res = replay(None, 3, 0.5)
>>> res = replay(lambda x: x.take(6).repeat(), 3, 0.5)
Parameters
  • mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] Selector function which can use the multicasted source sequence as many times as needed, without causing multiple subscriptions to the source sequence. Subscribers to the given source will receive all the notifications of the source subject to the specified replay buffer trimming policy.

  • buffer_size (Optional[int]) – [Optional] Maximum element count of the replay buffer.

  • window (Union[timedelta, float, None]) – [Optional] Maximum time length of the replay buffer.

  • scheduler (Optional[Scheduler]) – [Optional] Scheduler the observers are invoked on.

Return type

Callable[[Observable], Union[Observable, ConnectableObservable]]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements of a sequence produced by multicasting the source sequence within a mapper function.

rx.operators.retry(retry_count=None)

Repeats the source observable sequence the specified number of times or until it successfully terminates. If the retry count is not specified, it retries indefinitely.

Examples

>>> retried = retry()
>>> retried = retry(42)
Parameters

retry_count (Optional[int]) – [Optional] Number of times to retry the sequence. If not provided, retry the sequence indefinitely.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.

rx.operators.sample(sampler, scheduler=None)

Samples the observable sequence at each interval.

sample

Examples

>>> res = sample(sample_observable) # Sampler tick sequence
>>> res = sample(5.0) # 5 seconds
Parameters
  • sampler (Union[timedelta, float, Observable]) – Observable used to sample the source observable or time interval at which to sample (specified as a float denoting seconds or an instance of timedelta).

  • scheduler (Optional[Scheduler]) – Scheduler to use only when a time interval is given.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns a sampled observable sequence.

rx.operators.scan(accumulator, seed=<class 'rx.internal.utils.NotSet'>)

The scan operator.

Applies an accumulator function over an observable sequence and returns each intermediate result. The optional seed value is used as the initial accumulator value. For aggregation behavior with no intermediate results, see aggregate() or Observable().

scan

Examples

>>> scanned = source.scan(lambda acc, x: acc + x)
>>> scanned = source.scan(lambda acc, x: acc + x, 0)
Parameters
  • accumulator (Callable[[~TState, ~T1], ~TState]) – An accumulator function to be invoked on each element.

  • seed (Any) – [Optional] The initial accumulator value.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns an observable sequence containing the accumulated values.

rx.operators.sequence_equal(second, comparer=None)

Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.

scan

Examples

>>> res = sequence_equal([1,2,3])
>>> res = sequence_equal([{ "value": 42 }], lambda x, y: x.value == y.value)
>>> res = sequence_equal(rx.return_value(42))
>>> res = sequence_equal(rx.return_value({ "value": 42 }), lambda x, y: x.value == y.value)
Parameters
  • second (Observable) – Second observable sequence or array to compare.

  • comparer (Optional[Callable[[~T1, ~T2], bool]]) – [Optional] Comparer used to compare elements of both sequences. No guarantees on order of comparer arguments.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the specified equality comparer.

rx.operators.share()

Share a single subscription among multiple observers.

This is an alias for a composed publish() and ref_count().

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns a new Observable that multicasts (shares) the original Observable. As long as there is at least one Subscriber this Observable will be subscribed and emitting data. When all subscribers have unsubscribed it will unsubscribe from the source Observable.

rx.operators.single(predicate=None)

The single operator.

Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.

single

Example

>>> res = single()
>>> res = single(lambda x: x == 42)
Parameters

predicate (Optional[Callable[[~T1], bool]]) – [Optional] A predicate function to evaluate for elements in the source sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the single element in the observable sequence that satisfies the condition in the predicate.

rx.operators.single_or_default(predicate=None, default_value=None)

Returns the only element of an observable sequence that matches the predicate, or a default value if no such element exists this method reports an exception if there is more than one element in the observable sequence.

single_or_default

Examples

>>> res = single_or_default()
>>> res = single_or_default(lambda x: x == 42)
>>> res = single_or_default(lambda x: x == 42, 0)
>>> res = single_or_default(None, 0)
Parameters
  • predicate (Optional[Callable[[~T1], bool]]) – [Optional] A predicate function to evaluate for elements in the source sequence.

  • default_value (Optional[Any]) – [Optional] The default value if the index is outside the bounds of the source sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.

rx.operators.skip(count)

The skip operator.

Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.

skip

Parameters

count (int) – The number of elements to skip before returning the remaining elements.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements that occur after the specified index in the input sequence.

rx.operators.skip_last(count)

The skip_last operator.

skip_last

Bypasses a specified number of elements at the end of an observable sequence.

This operator accumulates a queue with a length enough to store the first count elements. As more elements are received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.

Parameters
  • count (int) – Number of elements to bypass at the end of the source

  • sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the source sequence elements except for the bypassed ones at the end.

rx.operators.skip_last_with_time(duration, scheduler=None)

Skips elements for the specified duration from the end of the observable source sequence.

Example

>>> res = skip_last_with_time(5.0)

This operator accumulates a queue with a length enough to store elements received during the initial duration window. As more elements are received, elements older than the specified duration are taken from the queue and produced on the result sequence. This causes elements to be delayed with duration.

Parameters
  • duration (Union[timedelta, float]) – Duration for skipping elements from the end of the sequence.

  • scheduler (Optional[Scheduler]) – Scheduler to use for time handling.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence with the elements skipped during the

specified duration from the end of the source sequence.

rx.operators.skip_until(other)

Returns the values from the source observable sequence only after the other observable sequence produces a value.

skip_until

Parameters

other (Observable) – The observable sequence that triggers propagation of elements of the source sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the elements of the source sequence starting from the point the other sequence triggered propagation.

rx.operators.skip_until_with_time(start_time, scheduler=None)

Skips elements from the observable source sequence until the specified start time. Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the start time.

skip_until

Examples

>>> res = skip_until_with_time(datetime())
>>> res = skip_until_with_time(5.0)
Parameters

start_time (Union[datetime, timedelta, float]) – Time to start taking elements from the source sequence. If this value is less than or equal to datetime.utcnow(), no elements will be skipped.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the elements skipped until the specified start time.

rx.operators.skip_while(predicate)

The skip_while operator.

Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements. The element’s index is used in the logic of the predicate function.

skip_while

Example

>>> skip_while(lambda value: value < 10)
Parameters

predicate (Callable[[~T1], bool]) – A function to test each element for a condition; the second parameter of the function represents the index of the source element.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.

rx.operators.skip_while_indexed(predicate)

Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements. The element’s index is used in the logic of the predicate function.

skip_while_indexed

Example

>>> skip_while(lambda value, index: value < 10 or index < 10)
Parameters

predicate (Callable[[~T1, int], bool]) – A function to test each element for a condition; the second parameter of the function represents the index of the source element.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.

rx.operators.skip_with_time(duration, scheduler=None)

Skips elements for the specified duration from the start of the observable source sequence.

skip_with_time

Parameters

res = skip_with_time (>>>) –

Specifying a zero value for duration doesn’t guarantee no elements will be dropped from the start of the source sequence. This is a side-effect of the asynchrony introduced by the scheduler, where the action that causes callbacks from the source sequence to be forwarded may not execute immediately, despite the zero due time.

Errors produced by the source sequence are always forwarded to the result sequence, even if the error occurs before the duration.

Parameters
  • duration (Union[timedelta, float]) – Duration for skipping elements from the start of the

  • sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the elements skipped during the specified duration from the start of the source sequence.

rx.operators.slice(start=None, stop=None, step=None)

The slice operator.

Slices the given observable. It is basically a wrapper around the operators skip, skip_last, take, take_last and filter.

slice

Examples

>>> result = source.slice(1, 10)
>>> result = source.slice(1, -2)
>>> result = source.slice(1, -1, 2)
Parameters
  • start (Optional[int]) – First element to take of skip last

  • stop (Optional[int]) – Last element to take of skip last

  • step (Optional[int]) – Takes every step element. Must be larger than zero

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns a sliced observable sequence.

rx.operators.some(predicate=None)

The some operator.

Determines whether some element of an observable sequence satisfies a condition if present, else if some items are in the sequence.

some

Examples

>>> result = source.some()
>>> result = source.some(lambda x: x > 3)
Parameters

predicate (Optional[Callable[[~T1], bool]]) – A function to test each element for a condition.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing a single element determining whether some elements in the source sequence pass the test in the specified predicate if given, else if some items are in the sequence.

rx.operators.starmap(mapper=None)

The starmap operator.

Unpack arguments grouped as tuple elements of an observable sequence and return an observable sequence of values by invoking the mapper function with star applied unpacked elements as positional arguments.

Use instead of map() when the the arguments to the mapper is grouped as tuples and the mapper function takes multiple arguments.

starmap

Example

>>> starmap(lambda x, y: x + y)
Parameters

mapper (Optional[Callable[[~T1], ~T2]]) – A transform function to invoke with unpacked elements as arguments.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the results of invoking the mapper function with unpacked elements of the source.

rx.operators.starmap_indexed(mapper=None)

Variant of starmap() which accepts an indexed mapper.

starmap_indexed

Example

>>> starmap_indexed(lambda x, y, i: x + y + i)
Parameters

mapper (Optional[Callable[[~T1, int], ~T2]]) – A transform function to invoke with unpacked elements as arguments.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the results of invoking the indexed mapper function with unpacked elements of the source.

rx.operators.start_with(*args)

Prepends a sequence of values to an observable sequence.

start_with

Example

>>> start_with(1, 2, 3)
Return type

Callable[[Observable], Observable]

Returns

An operator function that takes a source observable and returns the source sequence prepended with the specified values.

rx.operators.subscribe_on(scheduler)

Subscribe on the specified scheduler.

Wrap the source sequence in order to run its subscription and unsubscription logic on the specified scheduler. This operation is not commonly used; see the remarks section for more information on the distinction between subscribe_on and observe_on.

This only performs the side-effects of subscription and unsubscription on the specified scheduler. In order to invoke observer callbacks on a scheduler, use observe_on.

Parameters

scheduler (Scheduler) – Scheduler to perform subscription and unsubscription actions on.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns the source sequence whose subscriptions and un-subscriptions happen on the specified scheduler.

rx.operators.sum(key_mapper=None)

Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.

sum

Examples

>>> res = sum()
>>> res = sum(lambda x: x.value)
Parameters

key_mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] A transform function to apply to each element.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes a source observable and returns an observable sequence containing a single element with the sum of the values in the source sequence.

rx.operators.switch_latest()

The switch_latest operator.

Transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

switch_latest

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns the observable sequence that at any point in time produces the elements of the most recent inner observable sequence that has been received.

rx.operators.take(count)

Returns a specified number of contiguous elements from the start of an observable sequence.

take

Example

>>> op = take(5)
Parameters

count (int) – The number of elements to return.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the specified number of elements from the start of the input sequence.

rx.operators.take_last(count)

Returns a specified number of contiguous elements from the end of an observable sequence.

take_last

Example

>>> res = take_last(5)

This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.

Parameters
  • count (int) – Number of elements to take from the end of the source

  • sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the specified number of elements from the end of the source sequence.

rx.operators.take_last_buffer(count)

The take_last_buffer operator.

Returns an array with the specified number of contiguous elements from the end of an observable sequence.

take_last_buffer

Example

>>> res = source.take_last(5)

This operator accumulates a buffer with a length enough to store elements count elements. Upon completion of the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed.

Parameters
  • count (int) – Number of elements to take from the end of the source

  • sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing a single list with the specified number of elements from the end of the source sequence.

rx.operators.take_last_with_time(duration, scheduler=None)

Returns elements within the specified duration from the end of the observable source sequence.

take_last_with_time

Example

>>> res = take_last_with_time(5.0)

This operator accumulates a queue with a length enough to store elements received during the initial duration window. As more elements are received, elements older than the specified duration are taken from the queue and produced on the result sequence. This causes elements to be delayed with duration.

Parameters
  • duration (Union[timedelta, float]) – Duration for taking elements from the end of the

  • sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the elements taken during the specified duration from the end of the source sequence.

rx.operators.take_until(other)

Returns the values from the source observable sequence until the other observable sequence produces a value.

take_until

Parameters

other (Observable) – Observable sequence that terminates propagation of elements of the source sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns as observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.

rx.operators.take_until_with_time(end_time, scheduler=None)

Takes elements for the specified duration until the specified end time, using the specified scheduler to run timers.

take_until_with_time

Examples

>>> res = take_until_with_time(dt, [optional scheduler])
>>> res = take_until_with_time(5.0, [optional scheduler])
Parameters
  • end_time (Union[datetime, timedelta, float]) – Time to stop taking elements from the source sequence. If this value is less than or equal to datetime.utcnow(), the result stream will complete immediately.

  • scheduler (Optional[Scheduler]) – Scheduler to run the timer on.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the elements taken until the specified end time.

rx.operators.take_while(predicate, inclusive=False)

Returns elements from an observable sequence as long as a specified condition is true. The element’s index is used in the logic of the predicate function.

take_while

Example

>>> take_while(lambda value: value < 10)
Parameters
  • predicate (Callable[[~T1], bool]) – A function to test each element for a condition.

  • inclusive (bool) – [Optional] When set to True the value that caused the predicate function to return False will also be emitted. If not specified, defaults to False.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.

rx.operators.take_while_indexed(predicate, inclusive=False)

Returns elements from an observable sequence as long as a specified condition is true. The element’s index is used in the logic of the predicate function.

take_while_indexed

Example

>>> take_while_indexed(lambda value, index: value < 10 or index < 10)
Parameters
  • predicate (Callable[[~T1, int], bool]) – A function to test each element for a condition; the second parameter of the function represents the index of the source element.

  • inclusive (bool) – [Optional] When set to True the value that caused the predicate function to return False will also be emitted. If not specified, defaults to False.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.

rx.operators.take_with_time(duration, scheduler=None)

Takes elements for the specified duration from the start of the observable source sequence.

take_with_time

Example

>>> res = take_with_time(5.0)

This operator accumulates a queue with a length enough to store elements received during the initial duration window. As more elements are received, elements older than the specified duration are taken from the queue and produced on the result sequence. This causes elements to be delayed with duration.

Parameters

duration (Union[timedelta, float]) – Duration for taking elements from the start of the sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with the elements taken during the specified duration from the start of the source sequence.

rx.operators.throttle_first(window_duration, scheduler=None)

Returns an Observable that emits only the first item emitted by the source Observable during sequential time windows of a specified duration.

Parameters

window_duration (Union[timedelta, float]) – time to wait before emitting another item after emitting the last item.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable that performs the throttle operation.

rx.operators.throttle_with_mapper(throttle_duration_mapper)

The throttle_with_mapper operator.

Ignores values from an observable sequence which are followed by another value within a computed throttle duration.

Example

>>> op = throttle_with_mapper(lambda x: rx.Scheduler.timer(x+x))
Parameters
  • throttle_duration_mapper (Callable[[Any], Observable]) – Mapper function to retrieve an

  • sequence indicating the throttle duration for each (observable) –

  • element. (given) –

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns the throttled observable sequence.

rx.operators.timestamp(scheduler=None)

The timestamp operator.

Records the timestamp for each value in an observable sequence.

Examples

>>> timestamp()

Produces objects with attributes value and timestamp, where value is the original value.

Return type

Callable[[Observable], Observable]

Returns

A partially applied operator function that takes an observable source and returns an observable sequence with timestamp information on values.

rx.operators.timeout(duetime, other=None, scheduler=None)

Returns the source observable sequence or the other observable sequence if duetime elapses.

timeout

Examples

>>> res = timeout(5.0)
>>> res = timeout(datetime(), return_value(42))
>>> res = timeout(5.0, return_value(42))
Parameters
  • duetime (Union[datetime, float]) – Absolute (specified as a datetime object) or relative time (specified as a float denoting seconds or an instance of timedetla) when a timeout occurs.

  • other (Optional[Observable]) – Sequence to return in case of a timeout. If not specified, a timeout error throwing sequence will be used.

  • scheduler (Optional[Scheduler]) –

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes and observable source and returns the source sequence switching to the other sequence in case of a timeout.

rx.operators.timeout_with_mapper(first_timeout=None, timeout_duration_mapper=None, other=None)

Returns the source observable sequence, switching to the other observable sequence if a timeout is signaled.

Examples

>>> res = timeout_with_mapper(rx.timer(0.5))
>>> res = timeout_with_mapper(rx.timer(0.5), lambda x: rx.timer(0.2))
>>> res = timeout_with_mapper(rx.timer(0.5), lambda x: rx.timer(0.2)), rx.return_value(42))
Parameters
  • first_timeout (Optional[Observable]) – [Optional] Observable sequence that represents the timeout for the first element. If not provided, this defaults to rx.never().

  • timeout_duration_mapper (Optional[Callable[[Any], Observable]]) – [Optional] Selector to retrieve an observable sequence that represents the timeout between the current element and the next element.

  • other (Optional[Observable]) – [Optional] Sequence to return in case of a timeout. If not provided, this is set to rx.throw().

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns the source sequence switching to the other sequence in case of a timeout.

rx.operators.time_interval(scheduler=None)

Records the time interval between consecutive values in an observable sequence.

time_interval

Examples

>>> res = time_interval()
Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with time interval information on values.

rx.operators.to_dict(key_mapper, element_mapper=None)

Converts the observable sequence to a Map if it exists.

Parameters
  • key_mapper (Callable[[~T1], ~T2]) – A function which produces the key for the dictionary.

  • element_mapper (Optional[Callable[[~T1], ~T2]]) – [Optional] An optional function which produces the element for the dictionary. If not present, defaults to the value from the observable sequence.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with a single value of a dictionary containing the values from the observable sequence.

rx.operators.to_future(future_ctor=None)

Converts an existing observable sequence to a Future.

Example

op = to_future(asyncio.Future);

Parameters

future_ctor (Optional[Callable[[], Future]]) – [Optional] The constructor of the future.

Return type

Callable[[Observable], Future]

Returns

An operator function that takes an observable source and returns a future with the last value from the observable sequence.

rx.operators.to_iterable()

Creates an iterable from an observable sequence.

There is also an alias called to_list.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an obserable source and returns an observable sequence containing a single element with an iterable containing all the elements of the source sequence.

rx.operators.to_list()

Creates an iterable from an observable sequence.

There is also an alias called to_list.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an obserable source and returns an observable sequence containing a single element with an iterable containing all the elements of the source sequence.

rx.operators.to_marbles(timespan=0.1, scheduler=None)

Convert an observable sequence into a marble diagram string.

Parameters
  • timespan (Union[timedelta, float]) – [Optional] duration of each character in second. If not specified, defaults to 0.1s.

  • scheduler (Optional[Scheduler]) – [Optional] The scheduler used to run the the input sequence on.

Return type

Callable[[Observable], Observable]

Returns

Observable stream.

rx.operators.to_set()

Converts the observable sequence to a set.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence with a single value of a set containing the values from the observable sequence.

rx.operators.while_do(condition)

Repeats source as long as condition holds emulating a while loop.

Parameters

condition (Callable[[~T1], bool]) – The condition which determines if the source will be repeated.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence which is repeated as long as the condition holds.

rx.operators.window(boundaries)

Projects each element of an observable sequence into zero or more windows.

window

Examples

>>> res = window(rx.interval(1.0))
Parameters

boundaries (Observable) – Observable sequence whose elements denote the creation and completion of non-overlapping windows.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence of windows.

rx.operators.window_when(closing_mapper)

Projects each element of an observable sequence into zero or more windows.

window

Examples

>>> res = window(lambda: rx.timer(0.5))
Parameters

closing_mapper (Callable[[], Observable]) – A function invoked to define the closing of each produced window. It defines the boundaries of the produced windows (a window is started when the previous one is closed, resulting in non-overlapping windows).

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence of windows.

rx.operators.window_toggle(openings, closing_mapper)

Projects each element of an observable sequence into zero or more windows.

window

>>> res = window(rx.interval(0.5), lambda i: rx.timer(i))
Parameters
  • openings (Observable) – Observable sequence whose elements denote the creation of windows.

  • closing_mapper (Callable[[Any], Observable]) – A function invoked to define the closing of each produced window. Value from openings Observable that initiated the associated window is provided as argument to the function.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence of windows.

rx.operators.window_with_count(count, skip=None)

Projects each element of an observable sequence into zero or more windows which are produced based on element count information.

window_with_count

Examples

>>> window_with_count(10)
>>> window_with_count(10, 1)
Parameters
  • count (int) – Length of each window.

  • skip (Optional[int]) – [Optional] Number of elements to skip between creation of consecutive windows. If not specified, defaults to the count.

Return type

Callable[[Observable], Observable]

Returns

An observable sequence of windows.

rx.operators.with_latest_from(*sources)

The with_latest_from operator.

Merges the specified observable sequences into one observable sequence by creating a tuple only when the first observable sequence produces an element. The observables can be passed either as separate arguments or as a list.

with_latest_from

Examples

>>> op = with_latest_from(obs1)
>>> op = with_latest_from([obs1, obs2, obs3])
Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the result of combining elements of the sources into a tuple.

rx.operators.zip(*args)

Merges the specified observable sequences into one observable sequence by creating a tuple whenever all of the observable sequences have produced an element at a corresponding index.

zip

Example

>>> res = zip(obs1, obs2)
Parameters

args (Observable) – Observable sources to zip.

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes an observable source and returns an observable sequence containing the result of combining elements of the sources as a tuple.

rx.operators.zip_with_iterable(second)

Merges the specified observable sequence and list into one observable sequence by creating a tuple whenever all of the observable sequences have produced an element at a corresponding index.

zip_with_iterable

Example
>>> res = zip([1,2,3])
Parameters

second (Iterable[+T_co]) – Iterable to zip with the source observable..

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes and observable source and returns an observable sequence containing the result of combining elements of the sources as a tuple.

rx.operators.zip_with_list(second)

Merges the specified observable sequence and list into one observable sequence by creating a tuple whenever all of the observable sequences have produced an element at a corresponding index.

zip_with_iterable

Example
>>> res = zip([1,2,3])
Parameters

second (Iterable[+T_co]) – Iterable to zip with the source observable..

Return type

Callable[[Observable], Observable]

Returns

An operator function that takes and observable source and returns an observable sequence containing the result of combining elements of the sources as a tuple.