| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.internal.fuseable; |
| 15 |
|
| 16 |
import io.reactivex.rxjava3.annotations.NonNull; |
| 17 |
import io.reactivex.rxjava3.core.Observable; |
| 18 |
|
| 19 |
/** |
| 20 |
* Interface indicating a operator implementation can be macro-fused back to Observable in case |
| 21 |
* the operator goes from Observable to some other reactive type and then the sequence calls |
| 22 |
* for toObservable again: |
| 23 |
* <pre> |
| 24 |
* {@code |
| 25 |
* Single<Integer> single = Observable.range(1, 10).reduce((a, b) -> a + b); |
| 26 |
* Observable<Integer> observable = single.toObservable(); |
| 27 |
* } |
| 28 |
* </pre> |
| 29 |
* |
| 30 |
* The {@code Single.toObservable()} will check for this interface and call the {@link #fuseToObservable()} |
| 31 |
* to return an Observable which could be the Observable-specific implementation of reduce(BiFunction). |
| 32 |
* <p> |
| 33 |
* This causes a slight overhead in assembly time (1 instanceof check, 1 operator allocation and 1 dropped |
| 34 |
* operator) but does not incur the conversion overhead at runtime. |
| 35 |
* |
| 36 |
* @param <T> the value type |
| 37 |
*/ |
| 38 |
public interface FuseToObservable<@NonNull T> { |
| 39 |
|
| 40 |
/** |
| 41 |
* Returns a (direct) Observable for the operator. |
| 42 |
* <p>The implementation should handle the necessary RxJavaPlugins wrapping. |
| 43 |
* @return the Observable instance |
| 44 |
*/ |
| 45 |
@NonNull |
| 46 |
Observable<T> fuseToObservable(); |
| 47 |
} |