@@ -6657,6 +6657,32 @@ public final Single<T> elementAt(long index, T defaultItem) {
6657
6657
return RxJavaPlugins.onAssembly(new ObservableElementAtSingle<T>(this, index, defaultItem));
6658
6658
}
6659
6659
6660
+ /**
6661
+ * Returns a Single that emits the item found at a specified index in a sequence of emissions from a source ObservableSource.
6662
+ * If the source ObservableSource does not contain the item at the specified index a {@link NoSuchElementException} will be thrown.
6663
+ * <p>
6664
+ * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/elementAtOrError.png" alt="">
6665
+ * <dl>
6666
+ * <dt><b>Scheduler:</b></dt>
6667
+ * <dd>{@code elementAtOrError} does not operate by default on a particular {@link Scheduler}.</dd>
6668
+ * </dl>
6669
+ *
6670
+ * @param index
6671
+ * the zero-based index of the item to retrieve
6672
+ * @return a Single that emits the item at the specified position in the sequence emitted by the source
6673
+ * ObservableSource, or the default item if that index is outside the bounds of the source sequence
6674
+ * @throws IndexOutOfBoundsException
6675
+ * if {@code index} is less than 0
6676
+ * @see <a href="http://reactivex.io/documentation/operators/elementat.html">ReactiveX operators documentation: ElementAt</a>
6677
+ */
6678
+ @SchedulerSupport(SchedulerSupport.NONE)
6679
+ public final Single<T> elementAtOrError(long index) {
6680
+ if (index < 0) {
6681
+ throw new IndexOutOfBoundsException("index >= 0 required but it was " + index);
6682
+ }
6683
+ return RxJavaPlugins.onAssembly(new ObservableElementAtSingle<T>(this, index, null));
6684
+ }
6685
+
6660
6686
/**
6661
6687
* Filters items emitted by an ObservableSource by only emitting those that satisfy a specified predicate.
6662
6688
* <p>
@@ -6698,8 +6724,8 @@ public final Maybe<T> firstElement() {
6698
6724
}
6699
6725
6700
6726
/**
6701
- * Returns a Single that emits only the very first item emitted by the source ObservableSource, or a default
6702
- * item if the source ObservableSource completes without emitting anything .
6727
+ * Returns a Single that emits only the very first item emitted by the source ObservableSource, or a default item
6728
+ * if the source ObservableSource completes without emitting any items .
6703
6729
* <p>
6704
6730
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrDefault.png" alt="">
6705
6731
* <dl>
@@ -6717,6 +6743,24 @@ public final Single<T> first(T defaultItem) {
6717
6743
return elementAt(0L, defaultItem);
6718
6744
}
6719
6745
6746
+ /**
6747
+ * Returns a Single that emits only the very first item emitted by the source ObservableSource.
6748
+ * If the source ObservableSource completes without emitting any items a {@link NoSuchElementException} will be thrown.
6749
+ * <p>
6750
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/firstOrError.png" alt="">
6751
+ * <dl>
6752
+ * <dt><b>Scheduler:</b></dt>
6753
+ * <dd>{@code firstOrError} does not operate by default on a particular {@link Scheduler}.</dd>
6754
+ * </dl>
6755
+ *
6756
+ * @return the new Single instance
6757
+ * @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
6758
+ */
6759
+ @SchedulerSupport(SchedulerSupport.NONE)
6760
+ public final Single<T> firstOrError() {
6761
+ return elementAtOrError(0L);
6762
+ }
6763
+
6720
6764
/**
6721
6765
* Returns an Observable that emits items based on applying a function that you supply to each item emitted
6722
6766
* by the source ObservableSource, where that function returns an ObservableSource, and then merging those resulting
@@ -7660,7 +7704,7 @@ public final Maybe<T> lastElement() {
7660
7704
}
7661
7705
7662
7706
/**
7663
- * Returns an Observable that emits only the last item emitted by the source ObservableSource, or a default item
7707
+ * Returns a Single that emits only the last item emitted by the source ObservableSource, or a default item
7664
7708
* if the source ObservableSource completes without emitting any items.
7665
7709
* <p>
7666
7710
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/lastOrDefault.png" alt="">
@@ -7681,6 +7725,25 @@ public final Single<T> last(T defaultItem) {
7681
7725
return RxJavaPlugins.onAssembly(new ObservableLastSingle<T>(this, defaultItem));
7682
7726
}
7683
7727
7728
+ /**
7729
+ * Returns a Single that emits only the last item emitted by the source ObservableSource.
7730
+ * If the source ObservableSource completes without emitting any items a {@link NoSuchElementException} will be thrown.
7731
+ * <p>
7732
+ * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/lastOrError.png" alt="">
7733
+ * <dl>
7734
+ * <dt><b>Scheduler:</b></dt>
7735
+ * <dd>{@code lastOrError} does not operate by default on a particular {@link Scheduler}.</dd>
7736
+ * </dl>
7737
+ *
7738
+ * @return a Single that emits only the last item emitted by the source ObservableSource.
7739
+ * If the source ObservableSource completes without emitting any items a {@link NoSuchElementException} will be thrown.
7740
+ * @see <a href="http://reactivex.io/documentation/operators/last.html">ReactiveX operators documentation: Last</a>
7741
+ */
7742
+ @SchedulerSupport(SchedulerSupport.NONE)
7743
+ public final Single<T> lastOrError() {
7744
+ return RxJavaPlugins.onAssembly(new ObservableLastSingle<T>(this, null));
7745
+ }
7746
+
7684
7747
/**
7685
7748
* <strong>This method requires advanced knowledge about building operators; please consider
7686
7749
* other standard composition methods first;</strong>
@@ -9333,7 +9396,7 @@ public final Maybe<T> singleElement() {
9333
9396
}
9334
9397
9335
9398
/**
9336
- * Returns an Observable that emits the single item emitted by the source ObservableSource, if that ObservableSource
9399
+ * Returns a Single that emits the single item emitted by the source ObservableSource, if that ObservableSource
9337
9400
* emits only a single item, or a default item if the source ObservableSource emits no items. If the source
9338
9401
* ObservableSource emits more than one item, throw an {@code IllegalArgumentException}.
9339
9402
* <p>
@@ -9345,8 +9408,7 @@ public final Maybe<T> singleElement() {
9345
9408
*
9346
9409
* @param defaultItem
9347
9410
* a default value to emit if the source ObservableSource emits no item
9348
- * @return an Observable that emits the single item emitted by the source ObservableSource, or a default item if
9349
- * the source ObservableSource is empty
9411
+ * @return the new Single instance
9350
9412
* @throws IllegalArgumentException
9351
9413
* if the source ObservableSource emits more than one item
9352
9414
* @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
@@ -9357,6 +9419,30 @@ public final Single<T> single(T defaultItem) {
9357
9419
return RxJavaPlugins.onAssembly(new ObservableSingleSingle<T>(this, defaultItem));
9358
9420
}
9359
9421
9422
+ /**
9423
+ * Returns a Single that emits the single item emitted by the source ObservableSource, if that ObservableSource
9424
+ * emits only a single item.
9425
+ * If the source ObservableSource completes without emitting any items a {@link NoSuchElementException} will be thrown.
9426
+ * If the source ObservableSource emits more than one item, throw an {@code IllegalArgumentException}.
9427
+ * <p>
9428
+ * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/singleOrDefault.png" alt="">
9429
+ * <dl>
9430
+ * <dt><b>Scheduler:</b></dt>
9431
+ * <dd>{@code singleOrError} does not operate by default on a particular {@link Scheduler}.</dd>
9432
+ * </dl>
9433
+ *
9434
+ * @return the new Single instance
9435
+ * @throws IllegalArgumentException
9436
+ * if the source ObservableSource emits more than one item
9437
+ * @throws NoSuchElementException
9438
+ * if the source ObservableSource completes without emitting any items
9439
+ * @see <a href="http://reactivex.io/documentation/operators/first.html">ReactiveX operators documentation: First</a>
9440
+ */
9441
+ @SchedulerSupport(SchedulerSupport.NONE)
9442
+ public final Single<T> singleOrError() {
9443
+ return RxJavaPlugins.onAssembly(new ObservableSingleSingle<T>(this, null));
9444
+ }
9445
+
9360
9446
/**
9361
9447
* Returns an Observable that skips the first {@code count} items emitted by the source ObservableSource and emits
9362
9448
* the remainder.
0 commit comments