Filter

See also

  • Official ReactiveX documentation: Filter
Observable.filter(predicate)

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

Examples:

source.filter(lambda value: value < 10)
source.filter(lambda value, index: value < 10 or index < 10)
Parameters:
  • self (Observable) – Observable sequence to filter.
  • predicate – A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
Returns:

An observable sequence that contains elements from the input sequence that satisfy the condition.

Return type:

Observable

../../_images/filter.png
Observable.slice(start=None, stop=None, step=1)
Slices the given observable. It is basically a wrapper around the

operators skip(), skip_last(), take(), take_last() and filter().

This marble diagram helps you remember how slices works with streams. Positive numbers is relative to the start of the events, while negative numbers are relative to the end (on_completed) 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

Example: result = source.slice(1, 10) result = source.slice(1, -2) result = source.slice(1, -1, 2)

Keyword arguments: :param Observable self: Observable to slice :param int start: Number of elements to skip of take last :param int stop: Last element to take of skip last :param int step: Takes every step element. Must be larger than zero

returns:Returns a sliced observable sequence.
rtype:Observable
Observable.where(predicate)

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

Examples:

source.filter(lambda value: value < 10)
source.filter(lambda value, index: value < 10 or index < 10)
Parameters:
  • self (Observable) – Observable sequence to filter.
  • predicate – A function to test each source element for a condition; the second parameter of the function represents the index of the source element.
Returns:

An observable sequence that contains elements from the input sequence that satisfy the condition.

Return type:

Observable

../../_images/where.png