Table of Contents

Class LastOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Implements the Last operator. Mirrors rxjs's last.

public static class LastOperator
Inheritance
System.Object
LastOperator

Methods

Last<T>(Observable<T>)

Emits only the last value from source, once it completes.

public static Observable<T> Last<T>(this Observable<T> source)

Parameters

source Observable<T>

The source observable to take the last value from.

Returns

Observable<T>

An observable of just the last value from source.

Type Parameters

T

The element type of the source observable.

Remarks

If source completes without emitting any value, the result errors with an EmptyErrorException instead of completing — this is what distinguishes Last() from TakeLast(1).

Last<T>(Observable<T>, Func<T, bool>)

Emits only the last value from source that satisfies predicate, once source completes.

public static Observable<T> Last<T>(this Observable<T> source, Func<T, bool> predicate)

Parameters

source Observable<T>

The source observable to search.

predicate Func<T, bool>

A function that tests each value.

Returns

Observable<T>

An observable of the last value from source that satisfies predicate.

Type Parameters

T

The element type of the source observable.

Remarks

If no value satisfies predicate, the result errors with an EmptyErrorException. If predicate throws, that exception is forwarded via OnError instead.

Last<T>(Observable<T>, Func<T, bool>, T)

Emits only the last value from source that satisfies predicate, or defaultValue if none does before source completes.

public static Observable<T> Last<T>(this Observable<T> source, Func<T, bool> predicate, T defaultValue)

Parameters

source Observable<T>

The source observable to search.

predicate Func<T, bool>

A function that tests each value.

defaultValue T

The value to emit if no value satisfies predicate.

Returns

Observable<T>

An observable of the last matching value, or defaultValue if none is found.

Type Parameters

T

The element type of the source observable and the default value.

Remarks

If predicate throws, the exception is forwarded via OnError.

Last<T>(Observable<T>, Func<T, int, bool>)

Emits only the last value from source that satisfies predicate (called with the value and its zero-based emission index), once source completes.

public static Observable<T> Last<T>(this Observable<T> source, Func<T, int, bool> predicate)

Parameters

source Observable<T>

The source observable to search.

predicate Func<T, int, bool>

A function that tests each value together with its index since subscription.

Returns

Observable<T>

An observable of the last value from source that satisfies predicate.

Type Parameters

T

The element type of the source observable.

Remarks

If no value satisfies predicate, the result errors with an EmptyErrorException. If predicate throws, that exception is forwarded via OnError instead.

Last<T>(Observable<T>, Func<T, int, bool>, T)

Emits only the last value from source that satisfies predicate (called with the value and its zero-based emission index), or defaultValue if none does before source completes.

public static Observable<T> Last<T>(this Observable<T> source, Func<T, int, bool> predicate, T defaultValue)

Parameters

source Observable<T>

The source observable to search.

predicate Func<T, int, bool>

A function that tests each value together with its index since subscription.

defaultValue T

The value to emit if no value satisfies predicate.

Returns

Observable<T>

An observable of the last matching value, or defaultValue if none is found.

Type Parameters

T

The element type of the source observable and the default value.

Remarks

If predicate throws, the exception is forwarded via OnError.

Last<T>(Observable<T>, T)

Emits only the last value from source, or defaultValue if it completes without emitting any value.

public static Observable<T> Last<T>(this Observable<T> source, T defaultValue)

Parameters

source Observable<T>

The source observable to take the last value from.

defaultValue T

The value to emit if source completes without emitting anything.

Returns

Observable<T>

An observable of the last value from source, or defaultValue if it is empty.

Type Parameters

T

The element type of the source observable and the default value.