Class FirstOperator
Implements the First operator. Mirrors rxjs's first.
public static class FirstOperator
- Inheritance
-
System.ObjectFirstOperator
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
sourceObservable<T>The source observable to take the first value from.
Returns
- Observable<T>
An observable of just the first value from
source.
Type Parameters
TThe 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
sourceObservable<T>The source observable to search.
predicateFunc<T, bool>A function that tests each value.
Returns
- Observable<T>
An observable of the first value from
sourcethat satisfiespredicate.
Type Parameters
TThe 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
sourceObservable<T>The source observable to search.
predicateFunc<T, bool>A function that tests each value.
defaultValueTThe value to emit if no value satisfies
predicate.
Returns
- Observable<T>
An observable of the first matching value, or
defaultValueif none is found.
Type Parameters
TThe 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
sourceObservable<T>The source observable to search.
predicateFunc<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
sourcethat satisfiespredicate.
Type Parameters
TThe 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
sourceObservable<T>The source observable to search.
predicateFunc<T, int, bool>A function that tests each value together with its index since subscription.
defaultValueTThe value to emit if no value satisfies
predicate.
Returns
- Observable<T>
An observable of the first matching value, or
defaultValueif none is found.
Type Parameters
TThe 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
sourceObservable<T>The source observable to take the first value from.
defaultValueTThe value to emit if
sourcecompletes without emitting anything.
Returns
- Observable<T>
An observable of the first value from
source, ordefaultValueif it is empty.
Type Parameters
TThe element type of the source observable and the default value.