Table of Contents

Class FirstOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Implements the First operator. Mirrors rxjs's first.

public static class FirstOperator
Inheritance
System.Object
FirstOperator

Methods

First<T>(Observable<T>)

Emits only the first value from source, then completes immediately without waiting for source itself to complete.

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

Parameters

source Observable<T>

The source observable to take the first value from.

Returns

Observable<T>

An observable of just the first 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 First() from Take(1).

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

Emits only the first value from source that satisfies predicate, then completes.

public static Observable<T> First<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 first value from source that satisfies predicate.

Type Parameters

T

The element type of the source observable.

Remarks

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

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

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

public static Observable<T> First<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 first 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.

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

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

public static Observable<T> First<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 first value from source that satisfies predicate.

Type Parameters

T

The element type of the source observable.

Remarks

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

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

Emits only the first 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> First<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 first 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.

First<T>(Observable<T>, T)

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

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

Parameters

source Observable<T>

The source observable to take the first value from.

defaultValue T

The value to emit if source completes without emitting anything.

Returns

Observable<T>

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

Type Parameters

T

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