27
27
import io.reactivex.internal.fuseable.*;
28
28
import io.reactivex.internal.operators.flowable.*;
29
29
import io.reactivex.internal.operators.mixed.*;
30
- import io.reactivex.internal.operators.observable.ObservableFromPublisher ;
30
+ import io.reactivex.internal.operators.observable.* ;
31
31
import io.reactivex.internal.schedulers.ImmediateThinScheduler;
32
32
import io.reactivex.internal.subscribers.*;
33
33
import io.reactivex.internal.util.*;
@@ -8484,13 +8484,15 @@ public final Flowable<T> delaySubscription(long delay, TimeUnit unit, Scheduler
8484
8484
* <pre><code>
8485
8485
* Flowable.just(createOnNext(1), createOnComplete(), createOnNext(2))
8486
8486
* .doOnCancel(() -> System.out.println("Cancelled!"));
8487
+ * .dematerialize()
8487
8488
* .test()
8488
8489
* .assertResult(1);
8489
8490
* </code></pre>
8490
8491
* If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated
8491
8492
* with the same event.
8492
8493
* <pre><code>
8493
8494
* Flowable.just(createOnNext(1), createOnNext(2))
8495
+ * .dematerialize()
8494
8496
* .test()
8495
8497
* .assertResult(1, 2);
8496
8498
* </code></pre>
@@ -8508,14 +8510,74 @@ public final Flowable<T> delaySubscription(long delay, TimeUnit unit, Scheduler
8508
8510
* @return a Flowable that emits the items and notifications embedded in the {@link Notification} objects
8509
8511
* emitted by the source Publisher
8510
8512
* @see <a href="http://reactivex.io/documentation/operators/materialize-dematerialize.html">ReactiveX operators documentation: Dematerialize</a>
8513
+ * @see #dematerialize(Function)
8514
+ * @deprecated in 2.2.4; inherently type-unsafe as it overrides the output generic type. Use {@link #dematerialize(Function)} instead.
8511
8515
*/
8512
8516
@CheckReturnValue
8513
- @BackpressureSupport(BackpressureKind.FULL)
8514
8517
@SchedulerSupport(SchedulerSupport.NONE)
8518
+ @BackpressureSupport(BackpressureKind.PASS_THROUGH)
8519
+ @Deprecated
8520
+ @SuppressWarnings({ "unchecked", "rawtypes" })
8515
8521
public final <T2> Flowable<T2> dematerialize() {
8516
- @SuppressWarnings("unchecked")
8517
- Flowable<Notification<T2>> m = (Flowable<Notification<T2>>)this;
8518
- return RxJavaPlugins.onAssembly(new FlowableDematerialize<T2>(m));
8522
+ return RxJavaPlugins.onAssembly(new FlowableDematerialize(this, Functions.identity()));
8523
+ }
8524
+
8525
+ /**
8526
+ * Returns a Flowable that reverses the effect of {@link #materialize materialize} by transforming the
8527
+ * {@link Notification} objects extracted from the source items via a selector function
8528
+ * into their respective {@code Subscriber} signal types.
8529
+ * <p>
8530
+ * <img width="640" height="335" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/dematerialize.png" alt="">
8531
+ * <p>
8532
+ * The intended use of the {@code selector} function is to perform a
8533
+ * type-safe identity mapping (see example) on a source that is already of type
8534
+ * {@code Notification<T>}. The Java language doesn't allow
8535
+ * limiting instance methods to a certain generic argument shape, therefore,
8536
+ * a function is used to ensure the conversion remains type safe.
8537
+ * <p>
8538
+ * When the upstream signals an {@link Notification#createOnError(Throwable) onError} or
8539
+ * {@link Notification#createOnComplete() onComplete} item, the
8540
+ * returned Flowable cancels of the flow and terminates with that type of terminal event:
8541
+ * <pre><code>
8542
+ * Flowable.just(createOnNext(1), createOnComplete(), createOnNext(2))
8543
+ * .doOnCancel(() -> System.out.println("Canceled!"));
8544
+ * .dematerialize(notification -> notification)
8545
+ * .test()
8546
+ * .assertResult(1);
8547
+ * </code></pre>
8548
+ * If the upstream signals {@code onError} or {@code onComplete} directly, the flow is terminated
8549
+ * with the same event.
8550
+ * <pre><code>
8551
+ * Flowable.just(createOnNext(1), createOnNext(2))
8552
+ * .dematerialize(notification -> notification)
8553
+ * .test()
8554
+ * .assertResult(1, 2);
8555
+ * </code></pre>
8556
+ * If this behavior is not desired, the completion can be suppressed by applying {@link #concatWith(Publisher)}
8557
+ * with a {@link #never()} source.
8558
+ * <dl>
8559
+ * <dt><b>Backpressure:</b></dt>
8560
+ * <dd>The operator doesn't interfere with backpressure which is determined by the source {@code Publisher}'s
8561
+ * backpressure behavior.</dd>
8562
+ * <dt><b>Scheduler:</b></dt>
8563
+ * <dd>{@code dematerialize} does not operate by default on a particular {@link Scheduler}.</dd>
8564
+ * </dl>
8565
+ *
8566
+ * @param <R> the output value type
8567
+ * @param selector function that returns the upstream item and should return a Notification to signal
8568
+ * the corresponding {@code Subscriber} event to the downstream.
8569
+ * @return a Flowable that emits the items and notifications embedded in the {@link Notification} objects
8570
+ * selected from the items emitted by the source Flowable
8571
+ * @see <a href="http://reactivex.io/documentation/operators/materialize-dematerialize.html">ReactiveX operators documentation: Dematerialize</a>
8572
+ * @since 2.2.4 - experimental
8573
+ */
8574
+ @Experimental
8575
+ @CheckReturnValue
8576
+ @SchedulerSupport(SchedulerSupport.NONE)
8577
+ @BackpressureSupport(BackpressureKind.PASS_THROUGH)
8578
+ public final <R> Flowable<R> dematerialize(Function<? super T, Notification<R>> selector) {
8579
+ ObjectHelper.requireNonNull(selector, "selector is null");
8580
+ return RxJavaPlugins.onAssembly(new FlowableDematerialize<T, R>(this, selector));
8519
8581
}
8520
8582
8521
8583
/**
@@ -11069,6 +11131,7 @@ public final <R> Flowable<R> map(Function<? super T, ? extends R> mapper) {
11069
11131
* @return a Flowable that emits items that are the result of materializing the items and notifications
11070
11132
* of the source Publisher
11071
11133
* @see <a href="http://reactivex.io/documentation/operators/materialize-dematerialize.html">ReactiveX operators documentation: Materialize</a>
11134
+ * @see #dematerialize(Function)
11072
11135
*/
11073
11136
@CheckReturnValue
11074
11137
@BackpressureSupport(BackpressureKind.FULL)
0 commit comments