Skip to content

Commit fe4acf2

Browse files
JakeWhartonakarnokd
authored andcommitted
Decouple stream operators from Function interface. (#4711)
This allows a single class to implement itself as an operator for all stream types. A similar change was recently made to the transformer types.
1 parent 637978c commit fe4acf2

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
lines changed

src/main/java/io/reactivex/CompletableOperator.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313

1414
package io.reactivex;
1515

16-
import io.reactivex.functions.Function;
17-
1816
/**
19-
* Convenience interface and callback used by the lift operator that given a child CompletableSubscriber,
20-
* return a parent CompletableSubscriber that does any kind of lifecycle-related transformations.
17+
* Interface to map/wrap a downstream observer to an upstream observer.
2118
*/
22-
public interface CompletableOperator extends Function<CompletableObserver, CompletableObserver> {
23-
19+
public interface CompletableOperator {
20+
/**
21+
* Applies a function to the child CompletableObserver and returns a new parent CompletableObserver.
22+
* @param observer the child CompletableObservable instance
23+
* @return the parent CompletableObserver instance
24+
*/
25+
CompletableObserver apply(CompletableObserver observer) throws Exception;
2426
}

src/main/java/io/reactivex/FlowableOperator.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515

1616
import org.reactivestreams.Subscriber;
1717

18-
import io.reactivex.functions.Function;
19-
2018
/**
2119
* Interface to map/wrap a downstream subscriber to an upstream subscriber.
2220
*
2321
* @param <Downstream> the value type of the downstream
2422
* @param <Upstream> the value type of the upstream
2523
*/
26-
public interface FlowableOperator<Downstream, Upstream> extends Function<Subscriber<? super Downstream>, Subscriber<? super Upstream>> {
27-
24+
public interface FlowableOperator<Downstream, Upstream> {
25+
/**
26+
* Applies a function to the child Subscriber and returns a new parent Subscriber.
27+
* @param observer the child Subscriber instance
28+
* @return the parent Subscriber instance
29+
*/
30+
Subscriber<? super Upstream> apply(Subscriber<? super Downstream> observer) throws Exception;
2831
}

src/main/java/io/reactivex/MaybeOperator.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
package io.reactivex;
1515

16-
import io.reactivex.functions.Function;
17-
1816
/**
19-
* Interface to map/wrap a downstream subscriber to an upstream MaybeObserver.
17+
* Interface to map/wrap a downstream observer to an upstream observer.
2018
*
2119
* @param <Downstream> the value type of the downstream
2220
* @param <Upstream> the value type of the upstream
2321
*/
24-
public interface MaybeOperator<Downstream, Upstream> extends Function<MaybeObserver<? super Downstream>, MaybeObserver<? super Upstream>> {
25-
22+
public interface MaybeOperator<Downstream, Upstream> {
23+
/**
24+
* Applies a function to the child MaybeObserver and returns a new parent MaybeObserver.
25+
* @param observer the child MaybeObserver instance
26+
* @return the parent MaybeObserver instance
27+
*/
28+
MaybeObserver<? super Upstream> apply(MaybeObserver<? super Downstream> observer) throws Exception;
2629
}

src/main/java/io/reactivex/ObservableOperator.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
package io.reactivex;
1515

16-
import io.reactivex.functions.Function;
17-
1816
/**
19-
* Interface to map/wrap a downstream subscriber to an upstream Observer.
17+
* Interface to map/wrap a downstream observer to an upstream observer.
2018
*
2119
* @param <Downstream> the value type of the downstream
2220
* @param <Upstream> the value type of the upstream
2321
*/
24-
public interface ObservableOperator<Downstream, Upstream> extends Function<Observer<? super Downstream>, Observer<? super Upstream>> {
25-
22+
public interface ObservableOperator<Downstream, Upstream> {
23+
/**
24+
* Applies a function to the child Observer and returns a new parent Observer.
25+
* @param observer the child Observer instance
26+
* @return the parent Observer instance
27+
*/
28+
Observer<? super Upstream> apply(Observer<? super Downstream> observer) throws Exception;
2629
}

src/main/java/io/reactivex/SingleOperator.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313

1414
package io.reactivex;
1515

16-
import io.reactivex.functions.Function;
17-
1816
/**
19-
* Interface to map/wrap a downstream subscriber to an upstream SingleObserver.
17+
* Interface to map/wrap a downstream observer to an upstream observer.
2018
*
2119
* @param <Downstream> the value type of the downstream
2220
* @param <Upstream> the value type of the upstream
2321
*/
24-
public interface SingleOperator<Downstream, Upstream> extends Function<SingleObserver<? super Downstream>, SingleObserver<? super Upstream>> {
25-
22+
public interface SingleOperator<Downstream, Upstream> {
23+
/**
24+
* Applies a function to the child SingleObserver and returns a new parent SingleObserver.
25+
* @param observer the child SingleObserver instance
26+
* @return the parent SingleObserver instance
27+
*/
28+
SingleObserver<? super Upstream> apply(SingleObserver<? super Downstream> observer) throws Exception;
2629
}

0 commit comments

Comments
 (0)