Debian Codegraph @

src/main/java/io/reactivex/rxjava3/internal/fuseable/FuseToMaybe.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.Maybe;
18
19 /**
20 * Interface indicating an operator implementation can be macro-fused back to Maybe in case
21 * the operator goes from Maybe to some other reactive type and then the sequence calls
22 * for toMaybe again:
23 * <pre>
24 * {@code
25 * Single<Integer> single = Maybe.just(1).isEmpty();
26 * Maybe<Integer> maybe = single.toMaybe();
27 * }
28 * </pre>
29 *
30 * The {@code Single.toMaybe()} will check for this interface and call the {@link #fuseToMaybe()}
31 * to return a Maybe which could be the Maybe-specific implementation of isEmpty().
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 FuseToMaybe<@NonNull T> {
39
40 /**
41 * Returns a (direct) Maybe for the operator.
42 * <p>The implementation should handle the necessary RxJavaPlugins wrapping.
43 * @return the Maybe instance
44 */
45 @NonNull
46 Maybe<T> fuseToMaybe();
47 }