First
emit only the first item (or the first item that meets some condition) emitted by an Observable
See Also
- ElementAt
- Last
- Take
- Introduction to Rx: First
- Introduction to Rx: Single
- Loading data from multiple sources with RxJava by Dan Lew (example using Concat and First)
- RxMarbles:
find
- RxMarbles:
findIndex
- RxMarbles:
first
Language-Specific Information
RxGroovy first firstOrDefault latest mostRecent next single singleOrDefault takeFirst
In RxGroovy, this filtering operator is implemented as first
, firstOrDefault
, and takeFirst
.
Somewhat confusingly, there are also BlockingObservable
operators called first
and firstOrDefault
that block and then return items, rather than immediately returning Observables.
There are also several other operators that perform similar functions.
The Filtering Operators
first
, firstOrDefault
, single
, singleOrDefault
, and takeFirst
do not by default operate on any particular Scheduler.
The BlockingObservable
Methods
The BlockingObservable
methods do not transform an Observable into another, filtered Observable, but rather they break out of the Observable cascade, blocking until the Observable emits the desired item, and then return that item itself.
To turn an Observable into a BlockingObservable
so that you can use these methods, you can use either the Observable.toBlocking
or BlockingObservable.from
methods.
- Javadoc:
Observable.toBlocking()
- Javadoc:
BlockingObservable.from(Observable)
RxJava 1․x first firstOrDefault latest mostRecent next single singleOrDefault takeFirst
In RxJava, this filtering operator is implemented as first
, firstOrDefault
, and takeFirst
.
Somewhat confusingly, there are also BlockingObservable
operators called first
and firstOrDefault
that block and then return items, rather than immediately returning Observables.
There are also several other operators that perform similar functions.
The Filtering Operators
first
, firstOrDefault
, single
, singleOrDefault
, and takeFirst
do not by default operate on any particular Scheduler.
The BlockingObservable
Methods
The BlockingObservable
methods do not transform an Observable into another, filtered Observable, but rather they break out of the Observable cascade, blocking until the Observable emits the desired item, and then return that item itself.
To turn an Observable into a BlockingObservable
so that you can use these methods, you can use either the Observable.toBlocking
or BlockingObservable.from
methods.
- Javadoc:
Observable.toBlocking()
- Javadoc:
BlockingObservable.from(Observable)
RxJS find findIndex first single
find
, findIndex
, and first
are found in each of the following distributions:
rx.all.js
rx.all.compat.js
rx.aggregates.js
They each require one of the following distributions:
rx.js
rx.compat.js
rx.lite.js
rx.lite.compat.js
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/first.html