Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/fuseable/FuseToFlowable.java

raw
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.Flowable;
18
19 /**
20 * Interface indicating a operator implementation can be macro-fused back to Flowable in case
21 * the operator goes from Flowable to some other reactive type and then the sequence calls
22 * for toFlowable again:
23 * <pre>
24 * {@code
25 * Single<Integer> single = Flowable.range(1, 10).reduce((a, b) -> a + b);
26 * Flowable<Integer> flowable = single.toFlowable();
27 * }
28 * </pre>
29 *
30 * The {@code Single.toFlowable()} will check for this interface and call the {@link #fuseToFlowable()}
31 * to return a Flowable which could be the Flowable-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 FuseToFlowable<@NonNull T> {
39
40 /**
41 * Returns a (direct) Flowable for the operator.
42 * <p>The implementation should handle the necessary RxJavaPlugins wrapping.
43 * @return the Flowable instance
44 */
45 @NonNull
46 Flowable<T> fuseToFlowable();
47 }