diff --git a/docs/What's-different-in-3.0.md b/docs/What's-different-in-3.0.md index e936692c06..5d66960847 100644 --- a/docs/What's-different-in-3.0.md +++ b/docs/What's-different-in-3.0.md @@ -5,9 +5,56 @@ TBD. ### API signature changes +#### as() and to() operators + +In 2.x, the `to()` operator used the generic `Function` to allow assembly-time conversion of flows into arbitrary types. The drawback of this +approach was that each base reactive type had the same `Function` interface in their method signature, +thus it was impossible to implement multiple converters for different reactive types within the same class. +To work around this issue, the `as` operator and `XConverter` interfaces have been introduced +in 2.x, which interfaces are distinct and can be implemented on the same class. Changing the signature of `to` in 2.x was not possible due +to the pledged binary compatibility of the library. + +From 3.x, the `as()` methods have been removed and the `to()` methods now each work with their respective `XConverer` interfaces: + +- `Flowable.to(Function, R>)` is now `Flowable.to(FlowableConverter)` +- `Observable.to(Function, R>)` is now `Observable.to(ObservableConverter)` +- `Maybe.to(Function, R>)` is now `Maybe.to(MaybeConverter)` +- `Single.to(Function, R>)` is now `Maybe.to(SingleConverter)` +- `Completable.to(Function)` is now `Completable.to(CompletableConverter)` +- `ParallelFlowable.to(Function, R)` is now `ParallelFlowable.to(ParallelFlowableConverter)` + +If one was using these methods with a lambda expression, only a recompilation is needed: + +```java +// before +source.to(flowable -> flowable.blockingFirst()); + +// after +source.to(flowable -> flowable.blockingFirst()); +``` + +If one was implementing a Function interface (typically anonymously), the interface type, type arguments and the `throws` clause have to be adjusted + +```java +// before +source.to(new Function, Integer>() { + @Override + public Integer apply(Flowable t) throws Exception { + return t.blockingFirst(); + } +}); + +// after +source.to(new FlowableConverter() { + @Override + public Integer apply(Flowable t) { + return t.blockingFirst(); + } +}); +``` + TBD. -- as() merged into to() - some operators returning a more appropriate Single or Maybe - functional interfaces throws widening to Throwable - standard methods removed diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index c8a722f8e5..65c9e26918 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -27,7 +27,6 @@ import io.reactivex.internal.operators.maybe.*; import io.reactivex.internal.operators.mixed.*; import io.reactivex.internal.operators.single.*; -import io.reactivex.internal.util.ExceptionHelper; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; @@ -1182,29 +1181,6 @@ public final Completable andThen(CompletableSource next) { return RxJavaPlugins.onAssembly(new CompletableAndThenCompletable(this, next)); } - /** - * Calls the specified converter function during assembly time and returns its resulting value. - *

- * - *

- * This allows fluent conversion to any other type. - *

- *
Scheduler:
- *
{@code as} does not operate by default on a particular {@link Scheduler}.
- *
- *

History: 2.1.7 - experimental - * @param the resulting object type - * @param converter the function that receives the current Completable instance and returns a value - * @return the converted value - * @throws NullPointerException if converter is null - * @since 2.2 - */ - @CheckReturnValue - @SchedulerSupport(SchedulerSupport.NONE) - public final R as(@NonNull CompletableConverter converter) { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } - /** * Subscribes to and awaits the termination of this Completable instance in a blocking manner and * rethrows any exception emitted. @@ -2578,27 +2554,26 @@ private Completable timeout0(long timeout, TimeUnit unit, Scheduler scheduler, C } /** - * Allows fluent conversion to another type via a function callback. + * Calls the specified converter function during assembly time and returns its resulting value. *

* + *

+ * This allows fluent conversion to any other type. *

*
Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
*
- * @param the output type - * @param converter the function called with this which should return some other value. + *

History: 2.1.7 - experimental + * @param the resulting object type + * @param converter the function that receives the current Completable instance and returns a value * @return the converted value * @throws NullPointerException if converter is null + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - public final U to(Function converter) { - try { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - throw ExceptionHelper.wrapOrThrow(ex); - } + public final R to(@NonNull CompletableConverter converter) { + return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } /** diff --git a/src/main/java/io/reactivex/CompletableConverter.java b/src/main/java/io/reactivex/CompletableConverter.java index 1bea8631c8..b6f7c08a4e 100644 --- a/src/main/java/io/reactivex/CompletableConverter.java +++ b/src/main/java/io/reactivex/CompletableConverter.java @@ -16,7 +16,7 @@ import io.reactivex.annotations.*; /** - * Convenience interface and callback used by the {@link Completable#as} operator to turn a Completable into another + * Convenience interface and callback used by the {@link Completable#to} operator to turn a Completable into another * value fluently. *

History: 2.1.7 - experimental * @param the output type diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java index 601132a188..b6b0a21628 100644 --- a/src/main/java/io/reactivex/Flowable.java +++ b/src/main/java/io/reactivex/Flowable.java @@ -5646,30 +5646,6 @@ public final Single any(Predicate predicate) { return RxJavaPlugins.onAssembly(new FlowableAnySingle(this, predicate)); } - /** - * Calls the specified converter function during assembly time and returns its resulting value. - *

- * This allows fluent conversion to any other type. - *

- *
Backpressure:
- *
The backpressure behavior depends on what happens in the {@code converter} function.
- *
Scheduler:
- *
{@code as} does not operate by default on a particular {@link Scheduler}.
- *
- *

History: 2.1.7 - experimental - * @param the resulting object type - * @param converter the function that receives the current Flowable instance and returns a value - * @return the converted value - * @throws NullPointerException if converter is null - * @since 2.2 - */ - @CheckReturnValue - @BackpressureSupport(BackpressureKind.SPECIAL) - @SchedulerSupport(SchedulerSupport.NONE) - public final R as(@NonNull FlowableConverter converter) { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } - /** * Returns the first item emitted by this {@code Flowable}, or throws * {@code NoSuchElementException} if it emits no items. @@ -16878,20 +16854,18 @@ public final Flowable> timestamp(final TimeUnit unit, final Scheduler s *

Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
* + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Flowable instance and returns a value - * @return the value returned by the function + * @return the converted value + * @throws NullPointerException if converter is null + * @since 2.2 */ @CheckReturnValue @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerSupport.NONE) - public final R to(Function, R> converter) { - try { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - throw ExceptionHelper.wrapOrThrow(ex); - } + public final R to(@NonNull FlowableConverter converter) { + return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } /** diff --git a/src/main/java/io/reactivex/FlowableConverter.java b/src/main/java/io/reactivex/FlowableConverter.java index cf9176bf6d..60bc7cb1af 100644 --- a/src/main/java/io/reactivex/FlowableConverter.java +++ b/src/main/java/io/reactivex/FlowableConverter.java @@ -16,7 +16,7 @@ import io.reactivex.annotations.*; /** - * Convenience interface and callback used by the {@link Flowable#as} operator to turn a Flowable into another + * Convenience interface and callback used by the {@link Flowable#to} operator to turn a Flowable into another * value fluently. *

History: 2.1.7 - experimental * @param the upstream type diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index 762cf6535b..49017334c1 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -2279,27 +2279,6 @@ public final Maybe ambWith(MaybeSource other) { return ambArray(this, other); } - /** - * Calls the specified converter function during assembly time and returns its resulting value. - *

- * This allows fluent conversion to any other type. - *

- *
Scheduler:
- *
{@code as} does not operate by default on a particular {@link Scheduler}.
- *
- *

History: 2.1.7 - experimental - * @param the resulting object type - * @param converter the function that receives the current Maybe instance and returns a value - * @return the converted value - * @throws NullPointerException if converter is null - * @since 2.2 - */ - @CheckReturnValue - @SchedulerSupport(SchedulerSupport.NONE) - public final R as(@NonNull MaybeConverter converter) { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } - /** * Waits in a blocking fashion until the current Maybe signals a success value (which is returned), * null if completed or an exception (which is propagated). @@ -3579,28 +3558,24 @@ public final Maybe ofType(final Class clazz) { } /** - * Calls the specified converter function with the current Maybe instance - * during assembly time and returns its result. + * Calls the specified converter function during assembly time and returns its resulting value. + *

+ * This allows fluent conversion to any other type. *

*
Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
*
- * @param the result type - * @param convert the function that is called with the current Maybe instance during - * assembly time that should return some value to be the result - * - * @return the value returned by the convert function + *

History: 2.1.7 - experimental + * @param the resulting object type + * @param converter the function that receives the current Maybe instance and returns a value + * @return the converted value + * @throws NullPointerException if converter is null + * @since 2.2 */ @CheckReturnValue - @NonNull @SchedulerSupport(SchedulerSupport.NONE) - public final R to(Function, R> convert) { - try { - return ObjectHelper.requireNonNull(convert, "convert is null").apply(this); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - throw ExceptionHelper.wrapOrThrow(ex); - } + public final R to(@NonNull MaybeConverter converter) { + return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } /** diff --git a/src/main/java/io/reactivex/MaybeConverter.java b/src/main/java/io/reactivex/MaybeConverter.java index c997399d99..fe830ef1d7 100644 --- a/src/main/java/io/reactivex/MaybeConverter.java +++ b/src/main/java/io/reactivex/MaybeConverter.java @@ -16,7 +16,7 @@ import io.reactivex.annotations.*; /** - * Convenience interface and callback used by the {@link Maybe#as} operator to turn a Maybe into another + * Convenience interface and callback used by the {@link Maybe#to} operator to turn a Maybe into another * value fluently. *

History: 2.1.7 - experimental * @param the upstream type diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index 1b98b2328a..9a92fb7f65 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -5076,27 +5076,6 @@ public final Single any(Predicate predicate) { return RxJavaPlugins.onAssembly(new ObservableAnySingle(this, predicate)); } - /** - * Calls the specified converter function during assembly time and returns its resulting value. - *

- * This allows fluent conversion to any other type. - *

- *
Scheduler:
- *
{@code as} does not operate by default on a particular {@link Scheduler}.
- *
- *

History: 2.1.7 - experimental - * @param the resulting object type - * @param converter the function that receives the current Observable instance and returns a value - * @return the converted value - * @throws NullPointerException if converter is null - * @since 2.2 - */ - @CheckReturnValue - @SchedulerSupport(SchedulerSupport.NONE) - public final R as(@NonNull ObservableConverter converter) { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } - /** * Returns the first item emitted by this {@code Observable}, or throws * {@code NoSuchElementException} if it emits no items. @@ -13913,19 +13892,17 @@ public final Observable> timestamp(final TimeUnit unit, final Scheduler *

Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
* + *

History: 2.1.7 - experimental * @param the resulting object type * @param converter the function that receives the current Observable instance and returns a value - * @return the value returned by the function + * @return the converted value + * @throws NullPointerException if converter is null + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - public final R to(Function, R> converter) { - try { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - throw ExceptionHelper.wrapOrThrow(ex); - } + public final R to(@NonNull ObservableConverter converter) { + return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } /** diff --git a/src/main/java/io/reactivex/ObservableConverter.java b/src/main/java/io/reactivex/ObservableConverter.java index 12c461523d..2bdfec0b26 100644 --- a/src/main/java/io/reactivex/ObservableConverter.java +++ b/src/main/java/io/reactivex/ObservableConverter.java @@ -16,7 +16,7 @@ import io.reactivex.annotations.*; /** - * Convenience interface and callback used by the {@link Observable#as} operator to turn an Observable into another + * Convenience interface and callback used by the {@link Observable#to} operator to turn an Observable into another * value fluently. *

History: 2.1.7 - experimental * @param the upstream type diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index f0e2f32bb8..bc2227829f 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -1996,29 +1996,6 @@ public final Single ambWith(SingleSource other) { return ambArray(this, other); } - /** - * Calls the specified converter function during assembly time and returns its resulting value. - *

- * - *

- * This allows fluent conversion to any other type. - *

- *
Scheduler:
- *
{@code as} does not operate by default on a particular {@link Scheduler}.
- *
- *

History: 2.1.7 - experimental - * @param the resulting object type - * @param converter the function that receives the current Single instance and returns a value - * @return the converted value - * @throws NullPointerException if converter is null - * @since 2.2 - */ - @CheckReturnValue - @SchedulerSupport(SchedulerSupport.NONE) - public final R as(@NonNull SingleConverter converter) { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } - /** * Hides the identity of the current Single, including the Disposable that is sent * to the downstream via {@code onSubscribe()}. @@ -3851,29 +3828,26 @@ private Single timeout0(final long timeout, final TimeUnit unit, final Schedu } /** - * Calls the specified converter function with the current Single instance - * during assembly time and returns its result. + * Calls the specified converter function during assembly time and returns its resulting value. *

* + *

+ * This allows fluent conversion to any other type. *

*
Scheduler:
*
{@code to} does not operate by default on a particular {@link Scheduler}.
*
- * @param the result type - * @param convert the function that is called with the current Single instance during - * assembly time that should return some value to be the result - * - * @return the value returned by the convert function + *

History: 2.1.7 - experimental + * @param the resulting object type + * @param converter the function that receives the current Single instance and returns a value + * @return the converted value + * @throws NullPointerException if converter is null + * @since 2.2 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - public final R to(Function, R> convert) { - try { - return ObjectHelper.requireNonNull(convert, "convert is null").apply(this); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - throw ExceptionHelper.wrapOrThrow(ex); - } + public final R to(@NonNull SingleConverter converter) { + return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } /** diff --git a/src/main/java/io/reactivex/SingleConverter.java b/src/main/java/io/reactivex/SingleConverter.java index 1e3944f73b..a22f641f3b 100644 --- a/src/main/java/io/reactivex/SingleConverter.java +++ b/src/main/java/io/reactivex/SingleConverter.java @@ -16,7 +16,7 @@ import io.reactivex.annotations.*; /** - * Convenience interface and callback used by the {@link Single#as} operator to turn a Single into another + * Convenience interface and callback used by the {@link Single#to} operator to turn a Single into another * value fluently. *

History: 2.1.7 - experimental * @param the upstream type diff --git a/src/main/java/io/reactivex/parallel/ParallelFlowable.java b/src/main/java/io/reactivex/parallel/ParallelFlowable.java index 26eb676f22..ce859a5326 100644 --- a/src/main/java/io/reactivex/parallel/ParallelFlowable.java +++ b/src/main/java/io/reactivex/parallel/ParallelFlowable.java @@ -15,16 +15,16 @@ import java.util.*; +import org.reactivestreams.*; + import io.reactivex.*; import io.reactivex.annotations.*; -import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.*; import io.reactivex.internal.functions.*; import io.reactivex.internal.operators.parallel.*; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; -import org.reactivestreams.*; /** * Abstract base class for Parallel publishers that take an array of Subscribers. @@ -120,23 +120,6 @@ public static ParallelFlowable from(@NonNull Publisher sourc return RxJavaPlugins.onAssembly(new ParallelFromPublisher(source, parallelism, prefetch)); } - /** - * Calls the specified converter function during assembly time and returns its resulting value. - *

- * This allows fluent conversion to any other type. - *

History: 2.1.7 - experimental - * @param the resulting object type - * @param converter the function that receives the current ParallelFlowable instance and returns a value - * @return the converted value - * @throws NullPointerException if converter is null - * @since 2.2 - */ - @CheckReturnValue - @NonNull - public final R as(@NonNull ParallelFlowableConverter converter) { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } - /** * Maps the source values on each 'rail' to another value. *

@@ -761,22 +744,20 @@ public static ParallelFlowable fromArray(@NonNull Publisher... publish } /** - * Perform a fluent transformation to a value via a converter function which - * receives this ParallelFlowable. - * - * @param the output value type - * @param converter the converter function from ParallelFlowable to some type - * @return the value returned by the converter function + * Calls the specified converter function during assembly time and returns its resulting value. + *

+ * This allows fluent conversion to any other type. + *

History: 2.1.7 - experimental + * @param the resulting object type + * @param converter the function that receives the current ParallelFlowable instance and returns a value + * @return the converted value + * @throws NullPointerException if converter is null + * @since 2.2 */ @CheckReturnValue @NonNull - public final U to(@NonNull Function, U> converter) { - try { - return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); - } catch (Throwable ex) { - Exceptions.throwIfFatal(ex); - throw ExceptionHelper.wrapOrThrow(ex); - } + public final R to(@NonNull ParallelFlowableConverter converter) { + return ObjectHelper.requireNonNull(converter, "converter is null").apply(this); } /** diff --git a/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java b/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java index 9d1b287849..ddb8d7a545 100644 --- a/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java +++ b/src/main/java/io/reactivex/parallel/ParallelFlowableConverter.java @@ -16,7 +16,7 @@ import io.reactivex.annotations.*; /** - * Convenience interface and callback used by the {@link ParallelFlowable#as} operator to turn a ParallelFlowable into + * Convenience interface and callback used by the {@link ParallelFlowable#to} operator to turn a ParallelFlowable into * another value fluently. *

History: 2.1.7 - experimental * @param the upstream type diff --git a/src/test/java/io/reactivex/ConverterTest.java b/src/test/java/io/reactivex/ConverterTest.java index d2f174cd2f..16810e47c0 100644 --- a/src/test/java/io/reactivex/ConverterTest.java +++ b/src/test/java/io/reactivex/ConverterTest.java @@ -25,7 +25,7 @@ public final class ConverterTest { @Test public void flowableConverterThrows() { try { - Flowable.just(1).as(new FlowableConverter() { + Flowable.just(1).to(new FlowableConverter() { @Override public Integer apply(Flowable v) { throw new TestException("Forced failure"); @@ -40,7 +40,7 @@ public Integer apply(Flowable v) { @Test public void observableConverterThrows() { try { - Observable.just(1).as(new ObservableConverter() { + Observable.just(1).to(new ObservableConverter() { @Override public Integer apply(Observable v) { throw new TestException("Forced failure"); @@ -55,7 +55,7 @@ public Integer apply(Observable v) { @Test public void singleConverterThrows() { try { - Single.just(1).as(new SingleConverter() { + Single.just(1).to(new SingleConverter() { @Override public Integer apply(Single v) { throw new TestException("Forced failure"); @@ -70,7 +70,7 @@ public Integer apply(Single v) { @Test public void maybeConverterThrows() { try { - Maybe.just(1).as(new MaybeConverter() { + Maybe.just(1).to(new MaybeConverter() { @Override public Integer apply(Maybe v) { throw new TestException("Forced failure"); @@ -85,7 +85,7 @@ public Integer apply(Maybe v) { @Test public void completableConverterThrows() { try { - Completable.complete().as(new CompletableConverter() { + Completable.complete().to(new CompletableConverter() { @Override public Completable apply(Completable v) { throw new TestException("Forced failure"); @@ -104,7 +104,7 @@ public Completable apply(Completable v) { public void observableGenericsSignatureTest() { A a = new A() { }; - Observable.just(a).as((ObservableConverter)ConverterTest.testObservableConverterCreator()); + Observable.just(a).to((ObservableConverter)ConverterTest.testObservableConverterCreator()); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -112,7 +112,7 @@ public void observableGenericsSignatureTest() { public void singleGenericsSignatureTest() { A a = new A() { }; - Single.just(a).as((SingleConverter)ConverterTest.testSingleConverterCreator()); + Single.just(a).to((SingleConverter)ConverterTest.testSingleConverterCreator()); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -120,7 +120,7 @@ public void singleGenericsSignatureTest() { public void maybeGenericsSignatureTest() { A a = new A() { }; - Maybe.just(a).as((MaybeConverter)ConverterTest.testMaybeConverterCreator()); + Maybe.just(a).to((MaybeConverter)ConverterTest.testMaybeConverterCreator()); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -128,7 +128,7 @@ public void maybeGenericsSignatureTest() { public void flowableGenericsSignatureTest() { A a = new A() { }; - Flowable.just(a).as((FlowableConverter)ConverterTest.testFlowableConverterCreator()); + Flowable.just(a).to((FlowableConverter)ConverterTest.testFlowableConverterCreator()); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -136,7 +136,7 @@ public void flowableGenericsSignatureTest() { public void parallelFlowableGenericsSignatureTest() { A a = new A() { }; - Flowable.just(a).parallel().as((ParallelFlowableConverter)ConverterTest.testParallelFlowableConverterCreator()); + Flowable.just(a).parallel().to((ParallelFlowableConverter)ConverterTest.testParallelFlowableConverterCreator()); } @Test @@ -144,33 +144,33 @@ public void compositeTest() { CompositeConverter converter = new CompositeConverter(); Flowable.just(1) - .as(converter) + .to(converter) .test() .assertValue(1); Observable.just(1) - .as(converter) + .to(converter) .test() .assertValue(1); Maybe.just(1) - .as(converter) + .to(converter) .test() .assertValue(1); Single.just(1) - .as(converter) + .to(converter) .test() .assertValue(1); Completable.complete() - .as(converter) + .to(converter) .test() .assertComplete(); Flowable.just(1) .parallel() - .as(converter) + .to(converter) .test() .assertValue(1); } diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index 420bbe3caf..ef76bf9812 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -2813,7 +2813,7 @@ public void timeoutOtherNull() { @Test(timeout = 5000) public void toNormal() { normal.completable - .to(new Function>() { + .to(new CompletableConverter>() { @Override public Flowable apply(Completable c) { return c.toFlowable(); @@ -2827,7 +2827,7 @@ public Flowable apply(Completable c) { @Test(timeout = 5000) public void asNormal() { normal.completable - .as(new CompletableConverter>() { + .to(new CompletableConverter>() { @Override public Flowable apply(Completable c) { return c.toFlowable(); @@ -2840,7 +2840,7 @@ public Flowable apply(Completable c) { @Test public void as() { - Completable.complete().as(new CompletableConverter>() { + Completable.complete().to(new CompletableConverter>() { @Override public Flowable apply(Completable v) { return v.toFlowable(); @@ -2855,11 +2855,6 @@ public void toNull() { normal.completable.to(null); } - @Test(expected = NullPointerException.class) - public void asNull() { - normal.completable.as(null); - } - @Test(timeout = 5000) public void toFlowableNormal() { normal.completable.toFlowable().blockingForEach(Functions.emptyConsumer()); diff --git a/src/test/java/io/reactivex/flowable/FlowableConversionTest.java b/src/test/java/io/reactivex/flowable/FlowableConversionTest.java index 36bcb643f6..032fdf5e7e 100644 --- a/src/test/java/io/reactivex/flowable/FlowableConversionTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableConversionTest.java @@ -131,9 +131,9 @@ public void subscribe(Subscriber subscriber) { } } - public static class ConvertToCylonDetector implements Function, CylonDetectorObservable> { + public static class ConvertToCylonDetector implements FlowableConverter> { @Override - public CylonDetectorObservable apply(final Publisher onSubscribe) { + public CylonDetectorObservable apply(final Flowable onSubscribe) { return CylonDetectorObservable.create(onSubscribe); } } @@ -225,7 +225,7 @@ public Integer apply(Integer k) { }); } }) - .to(new Function, ConcurrentLinkedQueue>() { + .to(new FlowableConverter>() { @Override public ConcurrentLinkedQueue apply(Flowable onSubscribe) { final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); diff --git a/src/test/java/io/reactivex/flowable/FlowableNullTests.java b/src/test/java/io/reactivex/flowable/FlowableNullTests.java index 14e18460a8..159086048e 100644 --- a/src/test/java/io/reactivex/flowable/FlowableNullTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableNullTests.java @@ -2360,11 +2360,6 @@ public void toNull() { just1.to(null); } - @Test(expected = NullPointerException.class) - public void asNull() { - just1.as(null); - } - @Test(expected = NullPointerException.class) public void toListNull() { just1.toList(null); diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index 430fe50baf..749c83771c 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -1118,7 +1118,7 @@ public void testForEachWithNull() { public void testExtend() { final TestSubscriber subscriber = new TestSubscriber(); final Object value = new Object(); - Object returned = Flowable.just(value).to(new Function, Object>() { + Object returned = Flowable.just(value).to(new FlowableConverter() { @Override public Object apply(Flowable onSubscribe) { onSubscribe.subscribe(subscriber); @@ -1135,7 +1135,7 @@ public Object apply(Flowable onSubscribe) { public void testAsExtend() { final TestSubscriber subscriber = new TestSubscriber(); final Object value = new Object(); - Object returned = Flowable.just(value).as(new FlowableConverter() { + Object returned = Flowable.just(value).to(new FlowableConverter() { @Override public Object apply(Flowable onSubscribe) { onSubscribe.subscribe(subscriber); @@ -1150,7 +1150,7 @@ public Object apply(Flowable onSubscribe) { @Test public void as() { - Flowable.just(1).as(new FlowableConverter>() { + Flowable.just(1).to(new FlowableConverter>() { @Override public Observable apply(Flowable v) { return v.toObservable(); diff --git a/src/test/java/io/reactivex/maybe/MaybeTest.java b/src/test/java/io/reactivex/maybe/MaybeTest.java index c79f9211cf..fbeba59f91 100644 --- a/src/test/java/io/reactivex/maybe/MaybeTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeTest.java @@ -370,9 +370,9 @@ public void unsafeCreateNull() { @Test public void to() { - Maybe.just(1).to(new Function, Flowable>() { + Maybe.just(1).to(new MaybeConverter>() { @Override - public Flowable apply(Maybe v) throws Exception { + public Flowable apply(Maybe v) { return v.toFlowable(); } }) @@ -382,7 +382,7 @@ public Flowable apply(Maybe v) throws Exception { @Test public void as() { - Maybe.just(1).as(new MaybeConverter>() { + Maybe.just(1).to(new MaybeConverter>() { @Override public Flowable apply(Maybe v) { return v.toFlowable(); @@ -399,7 +399,7 @@ public void toNull() { @Test(expected = NullPointerException.class) public void asNull() { - Maybe.just(1).as(null); + Maybe.just(1).to(null); } @Test diff --git a/src/test/java/io/reactivex/observable/ObservableNullTests.java b/src/test/java/io/reactivex/observable/ObservableNullTests.java index 7445c8e3cf..4cd96d7932 100644 --- a/src/test/java/io/reactivex/observable/ObservableNullTests.java +++ b/src/test/java/io/reactivex/observable/ObservableNullTests.java @@ -2408,11 +2408,6 @@ public void toNull() { just1.to(null); } - @Test(expected = NullPointerException.class) - public void asNull() { - just1.as(null); - } - @Test(expected = NullPointerException.class) public void toListNull() { just1.toList(null); diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index 019dcf0ab3..2d49e5f6d4 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -1155,7 +1155,7 @@ public void testForEachWithNull() { public void testExtend() { final TestObserver to = new TestObserver(); final Object value = new Object(); - Object returned = Observable.just(value).to(new Function, Object>() { + Object returned = Observable.just(value).to(new ObservableConverter() { @Override public Object apply(Observable onSubscribe) { onSubscribe.subscribe(to); @@ -1172,7 +1172,7 @@ public Object apply(Observable onSubscribe) { public void testAsExtend() { final TestObserver to = new TestObserver(); final Object value = new Object(); - Object returned = Observable.just(value).as(new ObservableConverter() { + Object returned = Observable.just(value).to(new ObservableConverter() { @Override public Object apply(Observable onSubscribe) { onSubscribe.subscribe(to); @@ -1187,7 +1187,7 @@ public Object apply(Observable onSubscribe) { @Test public void as() { - Observable.just(1).as(new ObservableConverter>() { + Observable.just(1).to(new ObservableConverter>() { @Override public Flowable apply(Observable v) { return v.toFlowable(BackpressureStrategy.MISSING); diff --git a/src/test/java/io/reactivex/observers/ObserverFusion.java b/src/test/java/io/reactivex/observers/ObserverFusion.java index 05b694eba6..7137a47f05 100644 --- a/src/test/java/io/reactivex/observers/ObserverFusion.java +++ b/src/test/java/io/reactivex/observers/ObserverFusion.java @@ -13,7 +13,7 @@ package io.reactivex.observers; -import io.reactivex.Observable; +import io.reactivex.*; import io.reactivex.functions.*; import io.reactivex.internal.fuseable.*; @@ -40,7 +40,7 @@ public enum ObserverFusion { * @param cancelled should the TestObserver cancelled before the subscription even happens? * @return the new Function instance */ - public static Function, TestObserver> test( + public static ObservableConverter> test( final int mode, final boolean cancelled) { return new TestFunctionCallback(mode, cancelled); } @@ -76,7 +76,7 @@ public void accept(TestObserver to) throws Exception { } } - static final class TestFunctionCallback implements Function, TestObserver> { + static final class TestFunctionCallback implements ObservableConverter> { private final int mode; private final boolean cancelled; @@ -86,7 +86,7 @@ static final class TestFunctionCallback implements Function, Te } @Override - public TestObserver apply(Observable t) throws Exception { + public TestObserver apply(Observable t) { TestObserver to = new TestObserver(); to.setInitialFusionMode(mode); if (cancelled) { diff --git a/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java b/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java index 375013e022..d9c5087547 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java @@ -1088,21 +1088,7 @@ public void fromPublishers() { public void to() { Flowable.range(1, 5) .parallel() - .to(new Function, Flowable>() { - @Override - public Flowable apply(ParallelFlowable pf) throws Exception { - return pf.sequential(); - } - }) - .test() - .assertResult(1, 2, 3, 4, 5); - } - - @Test - public void as() { - Flowable.range(1, 5) - .parallel() - .as(new ParallelFlowableConverter>() { + .to(new ParallelFlowableConverter>() { @Override public Flowable apply(ParallelFlowable pf) { return pf.sequential(); @@ -1116,19 +1102,7 @@ public Flowable apply(ParallelFlowable pf) { public void toThrows() { Flowable.range(1, 5) .parallel() - .to(new Function, Flowable>() { - @Override - public Flowable apply(ParallelFlowable pf) throws Exception { - throw new TestException(); - } - }); - } - - @Test(expected = TestException.class) - public void asThrows() { - Flowable.range(1, 5) - .parallel() - .as(new ParallelFlowableConverter>() { + .to(new ParallelFlowableConverter>() { @Override public Flowable apply(ParallelFlowable pf) { throw new TestException(); diff --git a/src/test/java/io/reactivex/single/SingleNullTests.java b/src/test/java/io/reactivex/single/SingleNullTests.java index 0e9dbe871c..764517fdc9 100644 --- a/src/test/java/io/reactivex/single/SingleNullTests.java +++ b/src/test/java/io/reactivex/single/SingleNullTests.java @@ -844,11 +844,6 @@ public void toNull() { just1.to(null); } - @Test(expected = NullPointerException.class) - public void asNull() { - just1.as(null); - } - @Test(expected = NullPointerException.class) public void zipWithNull() { just1.zipWith(null, new BiFunction() { diff --git a/src/test/java/io/reactivex/single/SingleTest.java b/src/test/java/io/reactivex/single/SingleTest.java index 9e3d136c6d..1bc0919685 100644 --- a/src/test/java/io/reactivex/single/SingleTest.java +++ b/src/test/java/io/reactivex/single/SingleTest.java @@ -535,17 +535,7 @@ public Object apply(final Object[] o) throws Exception { @Test public void to() { - assertEquals(1, Single.just(1).to(new Function, Integer>() { - @Override - public Integer apply(Single v) throws Exception { - return 1; - } - }).intValue()); - } - - @Test - public void as() { - Single.just(1).as(new SingleConverter>() { + Single.just(1).to(new SingleConverter>() { @Override public Flowable apply(Single v) { return v.toFlowable(); diff --git a/src/test/java/io/reactivex/subscribers/SubscriberFusion.java b/src/test/java/io/reactivex/subscribers/SubscriberFusion.java index 02e1f3a9a5..8ca323c5a3 100644 --- a/src/test/java/io/reactivex/subscribers/SubscriberFusion.java +++ b/src/test/java/io/reactivex/subscribers/SubscriberFusion.java @@ -13,9 +13,9 @@ package io.reactivex.subscribers; -import io.reactivex.Flowable; -import io.reactivex.functions.*; -import io.reactivex.internal.fuseable.*; +import io.reactivex.*; +import io.reactivex.functions.Consumer; +import io.reactivex.internal.fuseable.QueueFuseable; /** * Utility methods that return functional interfaces to support assertions regarding fusion @@ -41,9 +41,9 @@ public enum SubscriberFusion { * @param cancelled should the TestSubscriber cancelled before the subscription even happens? * @return the new Function instance */ - public static Function, TestSubscriber> test( + public static FlowableConverter> test( final long initialRequest, final int mode, final boolean cancelled) { - return new TestFusionCheckFunction(mode, cancelled, initialRequest); + return new TestFusionCheckConverter(mode, cancelled, initialRequest); } /** * Returns a Consumer that asserts on its TestSubscriber parameter that @@ -76,19 +76,19 @@ public void accept(TestSubscriber ts) throws Exception { } } - static final class TestFusionCheckFunction implements Function, TestSubscriber> { + static final class TestFusionCheckConverter implements FlowableConverter> { private final int mode; private final boolean cancelled; private final long initialRequest; - TestFusionCheckFunction(int mode, boolean cancelled, long initialRequest) { + TestFusionCheckConverter(int mode, boolean cancelled, long initialRequest) { this.mode = mode; this.cancelled = cancelled; this.initialRequest = initialRequest; } @Override - public TestSubscriber apply(Flowable t) throws Exception { + public TestSubscriber apply(Flowable t) { TestSubscriber ts = new TestSubscriber(initialRequest); ts.setInitialFusionMode(mode); if (cancelled) {