/** * Transform a Single by applying a particular Transformer function to it. * <p> * This method operates on the Single itself whereas {@link #lift} operates on the Single's SingleObservers. * <p> * If the operator you are creating is designed to act on the individual item emitted by a Single, use * {@link #lift}. If your operator is designed to transform the source Single as a whole (for instance, by * applying a particular set of existing RxJava operators to it) use {@code compose}. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code compose} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param <R> the value type of the single returned by the transformer function * @param transformer the transformer function, not null * @return the source Single, transformed by the transformer function * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Implementing-Your-Own-Operators">RxJava wiki: Implementing Your Own Operators</a> */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final <R> Single<R> compose(SingleTransformer<? super T, ? extends R> transformer) { return wrap(((SingleTransformer<T, R>) ObjectHelper.requireNonNull(transformer, "transformer is null")).apply(this)); }
/** * Transform a Single by applying a particular Transformer function to it. * <p> * This method operates on the Single itself whereas {@link #lift} operates on the Single's SingleObservers. * <p> * If the operator you are creating is designed to act on the individual item emitted by a Single, use * {@link #lift}. If your operator is designed to transform the source Single as a whole (for instance, by * applying a particular set of existing RxJava operators to it) use {@code compose}. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code compose} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param <R> the value type of the single returned by the transformer function * @param transformer the transformer function, not null * @return the source Single, transformed by the transformer function * @see <a href="https://github.com/ReactiveX/RxJava/wiki/Implementing-Your-Own-Operators">RxJava wiki: Implementing Your Own Operators</a> */ @SuppressWarnings("unchecked") @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public final <R> Single<R> compose(SingleTransformer<? super T, ? extends R> transformer) { return wrap(((SingleTransformer<T, R>) ObjectHelper.requireNonNull(transformer, "transformer is null")).apply(this)); }
/** * Runs multiple Single sources and signals the events of the first one that signals (cancelling * the rest). * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code ambArray} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param <T> the value type * @param sources the array of sources. A subscription to each source will * occur in the same order as in this array. * @return the new Single instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static <T> Single<T> ambArray(final SingleSource<? extends T>... sources) { if (sources.length == 0) { return error(SingleInternalHelper.<T>emptyThrower()); } if (sources.length == 1) { return wrap((SingleSource<T>)sources[0]); } return RxJavaObservablePlugins.onAssembly(new SingleAmb<T>(sources, null)); }
/** * Runs multiple Single sources and signals the events of the first one that signals (cancelling * the rest). * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code ambArray} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * @param <T> the value type * @param sources the array of sources. A subscription to each source will * occur in the same order as in this array. * @return the new Single instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) @SuppressWarnings("unchecked") public static <T> Single<T> ambArray(final SingleSource<? extends T>... sources) { if (sources.length == 0) { return error(SingleInternalHelper.<T>emptyThrower()); } if (sources.length == 1) { return wrap((SingleSource<T>)sources[0]); } return RxJavaObservablePlugins.onAssembly(new SingleAmb<T>(sources, null)); }