Skip to content

Empty, Error and Never overloads with type witness #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion rxjava-core/src/main/java/rx/Observable.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,36 @@ public static <T> Observable<T> empty(Scheduler scheduler) {
return Observable.<T> empty().subscribeOn(scheduler);
}

/**
* Returns an Observable that emits no items to the {@link Observer} and
* immediately invokes its {@link Observer#onCompleted onCompleted} method.
* @param <T> the result type
* @param witness the witness to help the compiler infer the result type
* @return an Observable that returns no data to the {@link Observer} and
* immediately invokes the {@link Observer}'s
* {@link Observer#onCompleted() onCompleted} method
*/
public static <T> Observable<T> empty(T witness) {
return empty();
}

/**
* Returns an Observable that emits no items to the {@link Observer} and
* immediately invokes its {@link Observer#onCompleted onCompleted} method
* with the specified scheduler.
* @param <T> the result type
* @param scheduler the scheduler to call the
{@link Observer#onCompleted onCompleted} method
* @param witness the witness to help the compiler infer the result type
* @return an Observable that returns no data to the {@link Observer} and
* immediately invokes the {@link Observer}'s
* {@link Observer#onCompleted() onCompleted} method with the
* specified scheduler
*/
public static <T> Observable<T> empty(Scheduler scheduler, T witness) {
return empty(scheduler);
}

/**
* Returns an Observable that invokes an {@link Observer}'s
* {@link Observer#onError onError} method when the Observer subscribes to
Expand Down Expand Up @@ -714,6 +744,47 @@ public static <T> Observable<T> error(Throwable exception, Scheduler scheduler)
return Observable.<T> error(exception).subscribeOn(scheduler);
}

/**
* Returns an Observable that invokes an {@link Observer}'s
* {@link Observer#onError onError} method when the Observer subscribes to
* it.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/error.png">
*
* @param exception the particular error to report
* @param witness the value to help the compiler infer the value type
* @param <T> the type of the items (ostensibly) emitted by the Observable
* @return an Observable that invokes the {@link Observer}'s
* {@link Observer#onError onError} method when the Observer
* subscribes to it
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#empty-error-and-never">RxJava Wiki: error()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh244299.aspx">MSDN: Observable.Throw Method</a>
*/
public static <T> Observable<T> error(Throwable exception, T witness) {
return new ThrowObservable<T>(exception);
}

/**
* Returns an Observable that invokes an {@link Observer}'s
* {@link Observer#onError onError} method with the specified scheduler.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/error.s.png">
*
* @param exception the particular error to report
* @param scheduler the scheduler to call the
* {@link Observer#onError onError} method
* @param witness the value to help the compiler infer the value type
* @param <T> the type of the items (ostensibly) emitted by the Observable
* @return an Observable that invokes the {@link Observer}'s
* {@link Observer#onError onError} method with the specified
* scheduler
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#empty-error-and-never">RxJava Wiki: error()</a>
* @see <a href="http://msdn.microsoft.com/en-us/library/hh211711.aspx">MSDN: Observable.Throw Method</a>
*/
public static <T> Observable<T> error(Throwable exception, Scheduler scheduler, T witness) {
return Observable.<T> error(exception).subscribeOn(scheduler);
}

/**
* Converts an {@link Iterable} sequence into an Observable.
* <p>
Expand Down Expand Up @@ -1888,7 +1959,24 @@ public static <T> Observable<T> mergeDelayError(Observable<? extends T> t1, Obse
public static <T> Observable<T> never() {
return new NeverObservable<T>();
}


/**
* Returns an Observable that never sends any items or notifications to an
* {@link Observer}.
* <p>
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/never.png">
* <p>
* This Observable is useful primarily for testing purposes.
*
* @param <T> the type of items (not) emitted by the Observable
* @param witness the value to help the compiler infer the item type
* @return an Observable that never emits any items or sends any
* notifications to an {@link Observer}
* @see <a href="https://github.com/Netflix/RxJava/wiki/Creating-Observables#empty-error-and-never">RxJava Wiki: never()</a>
*/
public static <T> Observable<T> never(T witness) {
return new NeverObservable<T>();
}
/**
* Given an Observable that emits Observables, returns an Observable that
* emits the items emitted by the most recently emitted of those
Expand Down