Last

See also

  • Official ReactiveX documentation: Last
Observable.last(predicate=None)

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

Example: res = source.last() res = source.last(lambda x: x > 3)

Keyword arguments: predicate – {Function} [Optional] A predicate function to evaluate for

elements in the source sequence.

Returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.

../../_images/last.png ../../_images/B.last.p.png
Observable.last_or_default(predicate=None, default_value=None)

Return last or default element.

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

Examples: res = source.last_or_default() res = source.last_or_default(lambda x: x > 3) res = source.last_or_default(lambda x: x > 3, 0) res = source.last_or_default(None, 0)

predicate – {Function} [Optional] A predicate function to evaluate
for elements in the source sequence.
default_value – [Optional] The default value if no such element
exists. If not specified, defaults to None.

Returns {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.

../../_images/lastOrDefault.png ../../_images/B.lastOrDefault.p.png