Class Maybe<T>

    • Constructor Detail

      • Maybe

        public Maybe()
    • Method Detail

      • amb

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Maybe<T> amb​(@NonNull
                                                         @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
        Runs multiple MaybeSources provided by an Iterable sequence and signals the events of the first one that signals (disposing the rest).

        Scheduler:
        amb does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - the Iterable sequence of sources. A subscription to each source will occur in the same order as in the Iterable.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • ambArray

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        @SafeVarargs
        public static <@NonNull T> @NonNull Maybe<T> ambArray​(@NonNull
                                                              @NonNull MaybeSource<? extends @NonNull T>... sources)
        Runs multiple MaybeSources and signals the events of the first one that signals (disposing the rest).

        Scheduler:
        ambArray does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - the array of sources. A subscription to each source will occur in the same order as in the array.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if sources is null
      • concat

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Flowable<T> concat​(@NonNull
                                                               @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources,
                                                               int prefetch)
        Concatenate the single values, in a non-overlapping fashion, of the MaybeSource sources provided by a Publisher sequence as a Flowable sequence.

        Backpressure:
        The returned Flowable honors the backpressure of the downstream consumer and expects the Publisher to honor backpressure as well. If the sources Publisher violates this, a MissingBackpressureException is signaled.
        Scheduler:
        concat does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - the Publisher of MaybeSource instances
        prefetch - the number of MaybeSources to prefetch from the Publisher
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if prefetch is non-positive
      • concatArrayEager

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        @SafeVarargs
        public static <@NonNull T> @NonNull Flowable<T> concatArrayEager​(@NonNull
                                                                         @NonNull MaybeSource<? extends @NonNull T>... sources)
        Concatenates a sequence of MaybeSource eagerly into a Flowable sequence.

        Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source MaybeSources. The operator buffers the value emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSources that need to be eagerly concatenated
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
      • concatArrayEagerDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        @SafeVarargs
        public static <@NonNull T> @NonNull Flowable<T> concatArrayEagerDelayError​(@NonNull
                                                                                   @NonNull MaybeSource<? extends @NonNull T>... sources)
        Concatenates a sequence of MaybeSource eagerly into a Flowable sequence.

        Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source MaybeSources. The operator buffers the value emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSources that need to be eagerly concatenated
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
      • concatDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Flowable<T> concatDelayError​(@NonNull
                                                                         @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
        Concatenates the Iterable sequence of MaybeSources into a single sequence by subscribing to each MaybeSource, one after the other, one at a time and delays any errors till the all inner MaybeSources terminate as a Flowable sequence.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        concatDelayError does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element base type
        Parameters:
        sources - the Iterable sequence of MaybeSources
        Returns:
        the new Flowable with the concatenating behavior
        Throws:
        java.lang.NullPointerException - if sources is null
      • concatDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatDelayError​(@NonNull
                                                                         @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
        Concatenates the Publisher sequence of MaybeSources into a single sequence by subscribing to each inner MaybeSource, one after the other, one at a time and delays any errors till the all inner and the outer Publisher terminate as a Flowable sequence.

        Backpressure:
        concatDelayError fully supports backpressure.
        Scheduler:
        concatDelayError does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element base type
        Parameters:
        sources - the Publisher sequence of MaybeSources
        Returns:
        the new Flowable with the concatenating behavior
        Throws:
        java.lang.NullPointerException - if sources is null
      • concatDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatDelayError​(@NonNull
                                                                         @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources,
                                                                         int prefetch)
        Concatenates the Publisher sequence of MaybeSources into a single sequence by subscribing to each inner MaybeSource, one after the other, one at a time and delays any errors till the all inner and the outer Publisher terminate as a Flowable sequence.

        Backpressure:
        concatDelayError fully supports backpressure.
        Scheduler:
        concatDelayError does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element base type
        Parameters:
        sources - the Publisher sequence of MaybeSources
        prefetch - The number of upstream items to prefetch so that fresh items are ready to be mapped when a previous MaybeSource terminates. The operator replenishes after half of the prefetch amount has been consumed and turned into MaybeSources.
        Returns:
        the new Flowable with the concatenating behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if prefetch is non-positive
        Since:
        3.0.0
      • concatEager

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEager​(@NonNull
                                                                    @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
        Concatenates a sequence of MaybeSources eagerly into a Flowable sequence.

        Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source MaybeSources. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSource that need to be eagerly concatenated
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
      • concatEager

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEager​(@NonNull
                                                                    @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources,
                                                                    int maxConcurrency)
        Concatenates a sequence of MaybeSources eagerly into a Flowable sequence and runs a limited number of the inner sequences at once.

        Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source MaybeSources. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSource that need to be eagerly concatenated
        maxConcurrency - the maximum number of concurrently running inner MaybeSources; Integer.MAX_VALUE is interpreted as all inner MaybeSources can be active at the same time
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is non-positive
        Since:
        3.0.0
      • concatEager

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEager​(@NonNull
                                                                    @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
        Concatenates a Publisher sequence of MaybeSources eagerly into a Flowable sequence.

        Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source MaybeSources as they are observed. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream and the outer Publisher is expected to support backpressure. Violating this assumption, the operator will signal MissingBackpressureException.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSources that need to be eagerly concatenated
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
      • concatEager

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEager​(@NonNull
                                                                    @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources,
                                                                    int maxConcurrency)
        Concatenates a Publisher sequence of MaybeSources eagerly into a Flowable sequence, running at most the given number of inner MaybeSources at once.

        Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source MaybeSources as they are observed. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream and the outer Publisher is expected to support backpressure. Violating this assumption, the operator will signal MissingBackpressureException.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSources that need to be eagerly concatenated
        maxConcurrency - the maximum number of concurrently running inner MaybeSources; Integer.MAX_VALUE is interpreted as all inner MaybeSources can be active at the same time
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is non-positive
        Since:
        3.0.0
      • concatEagerDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError​(@NonNull
                                                                              @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
        Concatenates a sequence of MaybeSources eagerly into a Flowable sequence, delaying errors until all inner MaybeSources terminate.

        Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source MaybeSources. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSource that need to be eagerly concatenated
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
      • concatEagerDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError​(@NonNull
                                                                              @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources,
                                                                              int maxConcurrency)
        Concatenates a sequence of MaybeSources eagerly into a Flowable sequence, delaying errors until all inner MaybeSources terminate and runs a limited number of inner MaybeSources at once.

        Eager concatenation means that once an observer subscribes, this operator subscribes to all of the source MaybeSources. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSource that need to be eagerly concatenated
        maxConcurrency - the maximum number of concurrently running inner MaybeSources; Integer.MAX_VALUE is interpreted as all inner MaybeSources can be active at the same time
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is non-positive
        Since:
        3.0.0
      • concatEagerDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError​(@NonNull
                                                                              @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
        Concatenates a Publisher sequence of MaybeSources eagerly into a Flowable sequence, delaying errors until all the inner and the outer sequence terminate.

        Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source MaybeSources as they are observed. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream and the outer Publisher is expected to support backpressure. Violating this assumption, the operator will signal MissingBackpressureException.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSources that need to be eagerly concatenated
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
      • concatEagerDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> concatEagerDelayError​(@NonNull
                                                                              @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources,
                                                                              int maxConcurrency)
        Concatenates a Publisher sequence of MaybeSources eagerly into a Flowable sequence, delaying errors until all the inner and the outer sequence terminate and runs a limited number of the inner MaybeSources at once.

        Eager concatenation means that once a subscriber subscribes, this operator subscribes to all of the emitted source MaybeSources as they are observed. The operator buffers the values emitted by these MaybeSources and then drains them in order, each one after the previous one completes.

        Backpressure:
        Backpressure is honored towards the downstream and the outer Publisher is expected to support backpressure. Violating this assumption, the operator will signal MissingBackpressureException.
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        sources - a sequence of MaybeSources that need to be eagerly concatenated
        maxConcurrency - the maximum number of concurrently running inner MaybeSources; Integer.MAX_VALUE is interpreted as all inner MaybeSources can be active at the same time
        Returns:
        the new Flowable instance with the specified concatenation behavior
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is non-positive
        Since:
        3.0.0
      • create

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Maybe<T> create​(@NonNull
                                                            @NonNull MaybeOnSubscribe<@NonNull T> onSubscribe)
        Provides an API (via a cold Maybe) that bridges the reactive world with the callback-style world.

        Example:

        
         Maybe.<Event>create(emitter -> {
             Callback listener = new Callback() {
                 @Override
                 public void onEvent(Event e) {
                     if (e.isNothing()) {
                         emitter.onComplete();
                     } else {
                         emitter.onSuccess(e);
                     }
                 }
        
                 @Override
                 public void onFailure(Exception e) {
                     emitter.onError(e);
                 }
             };
        
             AutoCloseable c = api.someMethod(listener);
        
             emitter.setCancellable(c::close);
        
         });
         

        Whenever a MaybeObserver subscribes to the returned Maybe, the provided MaybeOnSubscribe callback is invoked with a fresh instance of a MaybeEmitter that will interact only with that specific MaybeObserver. If this MaybeObserver disposes the flow (making MaybeEmitter.isDisposed() return true), other observers subscribed to the same returned Maybe are not affected.

        Scheduler:
        create does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        onSubscribe - the emitter that is called when a MaybeObserver subscribes to the returned Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if onSubscribe is null
        See Also:
        MaybeOnSubscribe, Cancellable
      • fromCallable

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <T> @NonNull Maybe<@NonNull T> fromCallable​(@NonNull
                                                                  @NonNull java.util.concurrent.Callable<? extends @Nullable T> callable)
        Returns a Maybe that invokes the given Callable for each individual MaybeObserver that subscribes and emits the resulting non-null item via onSuccess while considering a null result from the Callable as indication for valueless completion via onComplete.

        This operator allows you to defer the execution of the given Callable until a MaybeObserver subscribes to the returned Maybe. In other terms, this source operator evaluates the given Callable "lazily".

        Note that the null handling of this operator differs from the similar source operators in the other base reactive classes. Those operators signal a NullPointerException if the value returned by their Callable is null while this fromCallable considers it to indicate the returned Maybe is empty.

        Scheduler:
        fromCallable does not operate by default on a particular Scheduler.
        Error handling:
        Any non-fatal exception thrown by Callable.call() will be forwarded to onError, except if the MaybeObserver disposed the subscription in the meantime. In this latter case, the exception is forwarded to the global error handler via RxJavaPlugins.onError(Throwable) wrapped into a UndeliverableException. Fatal exceptions are rethrown and usually will end up in the executing thread's Thread.UncaughtExceptionHandler.uncaughtException(Thread, Throwable) handler.
        Type Parameters:
        T - the type of the item emitted by the Maybe.
        Parameters:
        callable - a Callable instance whose execution should be deferred and performed for each individual MaybeObserver that subscribes to the returned Maybe.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if callable is null
        See Also:
        defer(Supplier), fromSupplier(Supplier)
      • fromFuture

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Maybe<T> fromFuture​(@NonNull
                                                                @NonNull java.util.concurrent.Future<? extends @NonNull T> future)
        Converts a Future into a Maybe, treating a null result as an indication of emptiness.

        The operator calls Future.get(), which is a blocking method, on the subscription thread. It is recommended applying subscribeOn(Scheduler) to move this blocking wait to a background thread, and if the Scheduler supports it, interrupt the wait when the flow is disposed.

        Unlike 1.x, disposing the Maybe won't cancel the future. If necessary, one can use composition to achieve the cancellation effect: futureMaybe.doOnDispose(() -> future.cancel(true));.

        Scheduler:
        fromFuture does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the type of object that the Future returns, and also the type of item to be emitted by the resulting Maybe
        Parameters:
        future - the source Future
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if future is null
        See Also:
        ReactiveX operators documentation: From, fromCompletionStage(CompletionStage)
      • fromFuture

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Maybe<T> fromFuture​(@NonNull
                                                                @NonNull java.util.concurrent.Future<? extends @NonNull T> future,
                                                                long timeout,
                                                                @NonNull
                                                                @NonNull java.util.concurrent.TimeUnit unit)
        Converts a Future into a Maybe, with a timeout on the Future.

        The operator calls Future.get(long, TimeUnit), which is a blocking method, on the subscription thread. It is recommended applying subscribeOn(Scheduler) to move this blocking wait to a background thread, and if the Scheduler supports it, interrupt the wait when the flow is disposed.

        Unlike 1.x, disposing the Maybe won't cancel the future. If necessary, one can use composition to achieve the cancellation effect: futureMaybe.doOnCancel(() -> future.cancel(true));.

        Scheduler:
        fromFuture does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the type of object that the Future returns, and also the type of item to be emitted by the resulting Maybe
        Parameters:
        future - the source Future
        timeout - the maximum time to wait before calling get
        unit - the TimeUnit of the timeout argument
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if future or unit is null
        See Also:
        ReactiveX operators documentation: From, fromCompletionStage(CompletionStage)
      • fromPublisher

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @BackpressureSupport(UNBOUNDED_IN)
        public static <@NonNull T> @NonNull Maybe<T> fromPublisher​(@NonNull
                                                                   @NonNull org.reactivestreams.Publisher<@NonNull T> source)
        Wraps a Publisher into a Maybe and emits the very first item or completes if the source is empty.

        Backpressure:
        The operator consumes the given Publisher in an unbounded manner (requesting Long.MAX_VALUE) but cancels it after one item received.
        Scheduler:
        fromPublisher does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the target type
        Parameters:
        source - the Publisher to convert from
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if source is null
        Since:
        3.0.0
      • fromRunnable

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Maybe<T> fromRunnable​(@NonNull
                                                                  @NonNull java.lang.Runnable run)
        Returns a Maybe instance that runs the given Runnable for each MaybeObserver and emits either its unchecked exception or simply completes.

        If the code to be wrapped needs to throw a checked or more broader Throwable exception, that exception has to be converted to an unchecked exception by the wrapped code itself. Alternatively, use the fromAction(Action) method which allows the wrapped code to throw any Throwable exception and will signal it to observers as-is.

        Scheduler:
        fromRunnable does not operate by default on a particular Scheduler.
        Error handling:
        If the Runnable throws an exception, the respective Throwable is delivered to the downstream via MaybeObserver.onError(Throwable), except when the downstream has disposed this Maybe source. In this latter case, the Throwable is delivered to the global error handler via RxJavaPlugins.onError(Throwable) as an UndeliverableException.
        Type Parameters:
        T - the target type
        Parameters:
        run - the Runnable to run for each MaybeObserver
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if run is null
        See Also:
        fromAction(Action)
      • fromSupplier

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <T> @NonNull Maybe<@NonNull T> fromSupplier​(@NonNull
                                                                  @NonNull Supplier<? extends @Nullable T> supplier)
        Returns a Maybe that invokes the given Supplier for each individual MaybeObserver that subscribes and emits the resulting non-null item via onSuccess while considering a null result from the Supplier as indication for valueless completion via onComplete.

        This operator allows you to defer the execution of the given Supplier until a MaybeObserver subscribes to the returned Maybe. In other terms, this source operator evaluates the given Supplier "lazily".

        Note that the null handling of this operator differs from the similar source operators in the other base reactive classes. Those operators signal a NullPointerException if the value returned by their Supplier is null while this fromSupplier considers it to indicate the returned Maybe is empty.

        Scheduler:
        fromSupplier does not operate by default on a particular Scheduler.
        Error handling:
        Any non-fatal exception thrown by Supplier.get() will be forwarded to onError, except if the MaybeObserver disposed the subscription in the meantime. In this latter case, the exception is forwarded to the global error handler via RxJavaPlugins.onError(Throwable) wrapped into a UndeliverableException. Fatal exceptions are rethrown and usually will end up in the executing thread's Thread.UncaughtExceptionHandler.uncaughtException(Thread, Throwable) handler.
        Type Parameters:
        T - the type of the item emitted by the Maybe.
        Parameters:
        supplier - a Supplier instance whose execution should be deferred and performed for each individual MaybeObserver that subscribes to the returned Maybe.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if supplier is null
        Since:
        3.0.0
        See Also:
        defer(Supplier), fromCallable(Callable)
      • merge

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> merge​(@NonNull
                                                              @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
        Merges an Iterable sequence of MaybeSource instances into a single Flowable sequence, running all MaybeSources at once.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        merge does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source MaybeSources signal a Throwable via onError, the resulting Flowable terminates with that Throwable and all other source MaybeSources are disposed. If more than one MaybeSource signals an error, the resulting Flowable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Flowable has been cancelled or terminated with a (composite) error will be sent to the same global error handler. Use mergeDelayError(Iterable) to merge sources and terminate only when all source MaybeSources have completed or failed with an error.
        Type Parameters:
        T - the common and resulting value type
        Parameters:
        sources - the Iterable sequence of MaybeSource sources
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        mergeDelayError(Iterable)
      • merge

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> merge​(@NonNull
                                                              @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
        Merges a Publisher sequence of MaybeSource instances into a single Flowable sequence, running all MaybeSources at once.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        merge does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source MaybeSources signal a Throwable via onError, the resulting Flowable terminates with that Throwable and all other source MaybeSources are disposed. If more than one MaybeSource signals an error, the resulting Flowable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Flowable has been cancelled or terminated with a (composite) error will be sent to the same global error handler. Use mergeDelayError(Publisher) to merge sources and terminate only when all source MaybeSources have completed or failed with an error.
        Type Parameters:
        T - the common and resulting value type
        Parameters:
        sources - the Flowable sequence of MaybeSource sources
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        mergeDelayError(Publisher)
      • merge

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Flowable<T> merge​(@NonNull
                                                              @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources,
                                                              int maxConcurrency)
        Merges a Publisher sequence of MaybeSource instances into a single Flowable sequence, running at most maxConcurrency MaybeSources at once.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        merge does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source MaybeSources signal a Throwable via onError, the resulting Flowable terminates with that Throwable and all other source MaybeSources are disposed. If more than one MaybeSource signals an error, the resulting Flowable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Flowable has been cancelled or terminated with a (composite) error will be sent to the same global error handler. Use mergeDelayError(Publisher, int) to merge sources and terminate only when all source MaybeSources have completed or failed with an error.
        Type Parameters:
        T - the common and resulting value type
        Parameters:
        sources - the Flowable sequence of MaybeSource sources
        maxConcurrency - the maximum number of concurrently running MaybeSources
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is non-positive
        See Also:
        mergeDelayError(Publisher, int)
      • merge

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Maybe<T> merge​(@NonNull
                                                           @NonNull MaybeSource<? extends MaybeSource<? extends @NonNull T>> source)
        Flattens a MaybeSource that emits a MaybeSource into a single MaybeSource that emits the item emitted by the nested MaybeSource, without any transformation.

        Scheduler:
        merge does not operate by default on a particular Scheduler.
        Error handling:
        The resulting Maybe emits the outer source's or the inner MaybeSource's Throwable as is. Unlike the other merge() operators, this operator won't and can't produce a CompositeException because there is only one possibility for the outer or the inner MaybeSource to emit an onError signal. Therefore, there is no need for a mergeDelayError(MaybeSource<MaybeSource<T>>) operator.
        Type Parameters:
        T - the value type of the sources and the output
        Parameters:
        source - a MaybeSource that emits a MaybeSource
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if source is null
        See Also:
        ReactiveX operators documentation: Merge
      • mergeArray

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @SafeVarargs
        public static <@NonNull T> @NonNull Flowable<T> mergeArray​(MaybeSource<? extends @NonNull T>... sources)
        Merges an array of MaybeSource instances into a single Flowable sequence, running all MaybeSources at once.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        mergeArray does not operate by default on a particular Scheduler.
        Error handling:
        If any of the source MaybeSources signal a Throwable via onError, the resulting Flowable terminates with that Throwable and all other source MaybeSources are disposed. If more than one MaybeSource signals an error, the resulting Flowable may terminate with the first one's error or, depending on the concurrency of the sources, may terminate with a CompositeException containing two or more of the various error signals. Throwables that didn't make into the composite will be sent (individually) to the global error handler via RxJavaPlugins.onError(Throwable) method as UndeliverableException errors. Similarly, Throwables signaled by source(s) after the returned Flowable has been cancelled or terminated with a (composite) error will be sent to the same global error handler. Use mergeArrayDelayError(MaybeSource...) to merge sources and terminate only when all source MaybeSources have completed or failed with an error.
        Type Parameters:
        T - the common and resulting value type
        Parameters:
        sources - the array sequence of MaybeSource sources
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        mergeArrayDelayError(MaybeSource...)
      • mergeArrayDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @SafeVarargs
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> mergeArrayDelayError​(@NonNull
                                                                             @NonNull MaybeSource<? extends @NonNull T>... sources)
        Flattens an array of MaybeSources into one Flowable, in a way that allows a subscriber to receive all successfully emitted items from each of the source MaybeSources without being interrupted by an error notification from one of them.

        This behaves like merge(Publisher) except that if any of the merged MaybeSources notify of an error via onError, mergeArrayDelayError will refrain from propagating that error notification until all of the merged MaybeSources have finished emitting items.

        Even if multiple merged MaybeSources send onError notifications, mergeArrayDelayError will only invoke the onError method of its subscribers once.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        mergeArrayDelayError does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element base type
        Parameters:
        sources - the array of MaybeSources
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        ReactiveX operators documentation: Merge
      • mergeDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> mergeDelayError​(@NonNull
                                                                        @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources)
        Flattens an Iterable sequence of MaybeSources into one Flowable, in a way that allows a subscriber to receive all successfully emitted items from each of the source MaybeSources without being interrupted by an error notification from one of them.

        This behaves like merge(Publisher) except that if any of the merged MaybeSources notify of an error via onError, mergeDelayError will refrain from propagating that error notification until all of the merged MaybeSources have finished emitting items.

        Even if multiple merged MaybeSources send onError notifications, mergeDelayError will only invoke the onError method of its subscribers once.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        mergeDelayError does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element base type
        Parameters:
        sources - the Iterable of MaybeSources
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        ReactiveX operators documentation: Merge
      • mergeDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Flowable<T> mergeDelayError​(@NonNull
                                                                        @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
        Flattens a Publisher that emits MaybeSources into one Flowable, in a way that allows a subscriber to receive all successfully emitted items from all of the source MaybeSources without being interrupted by an error notification from one of them or even the main Publisher.

        This behaves like merge(Publisher) except that if any of the merged MaybeSources notify of an error via onError, mergeDelayError will refrain from propagating that error notification until all of the merged MaybeSources and the main Publisher have finished emitting items.

        Even if multiple merged MaybeSources send onError notifications, mergeDelayError will only invoke the onError method of its subscribers once.

        Backpressure:
        The operator honors backpressure from downstream. The outer Publisher is consumed in unbounded mode (i.e., no backpressure is applied to it).
        Scheduler:
        mergeDelayError does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element base type
        Parameters:
        sources - a Publisher that emits MaybeSources
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        See Also:
        ReactiveX operators documentation: Merge
      • mergeDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Flowable<T> mergeDelayError​(@NonNull
                                                                        @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources,
                                                                        int maxConcurrency)
        Flattens a Publisher that emits MaybeSources into one Flowable, in a way that allows a subscriber to receive all successfully emitted items from all of the source MaybeSources without being interrupted by an error notification from one of them or even the main Publisher as well as limiting the total number of active MaybeSources.

        This behaves like merge(Publisher, int) except that if any of the merged MaybeSources notify of an error via onError, mergeDelayError will refrain from propagating that error notification until all of the merged MaybeSources and the main Publisher have finished emitting items.

        Even if multiple merged MaybeSources send onError notifications, mergeDelayError will only invoke the onError method of its subscribers once.

        Backpressure:
        The operator honors backpressure from downstream. The outer Publisher is consumed in unbounded mode (i.e., no backpressure is applied to it).
        Scheduler:
        mergeDelayError does not operate by default on a particular Scheduler.

        History: 2.1.9 - experimental

        Type Parameters:
        T - the common element base type
        Parameters:
        sources - a Publisher that emits MaybeSources
        maxConcurrency - the maximum number of active inner MaybeSources to be merged at a time
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        java.lang.IllegalArgumentException - if maxConcurrency is non-positive
        Since:
        2.2
        See Also:
        ReactiveX operators documentation: Merge
      • mergeDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Flowable<T> mergeDelayError​(@NonNull
                                                                        @NonNull MaybeSource<? extends @NonNull T> source1,
                                                                        @NonNull
                                                                        @NonNull MaybeSource<? extends @NonNull T> source2)
        Flattens two MaybeSources into one Flowable, in a way that allows a subscriber to receive all successfully emitted items from each of the source MaybeSources without being interrupted by an error notification from one of them.

        This behaves like merge(MaybeSource, MaybeSource) except that if any of the merged MaybeSources notify of an error via onError, mergeDelayError will refrain from propagating that error notification until all of the merged MaybeSources have finished emitting items.

        Even if both merged MaybeSources send onError notifications, mergeDelayError will only invoke the onError method of its subscribers once.

        Backpressure:
        The operator honors backpressure from downstream.
        Scheduler:
        mergeDelayError does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element base type
        Parameters:
        source1 - a MaybeSource to be merged
        source2 - a MaybeSource to be merged
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if source1 or source2 is null
        See Also:
        ReactiveX operators documentation: Merge
      • switchOnNextDelayError

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Flowable<T> switchOnNextDelayError​(@NonNull
                                                                               @NonNull org.reactivestreams.Publisher<? extends MaybeSource<? extends @NonNull T>> sources)
        Switches between MaybeSources emitted by the source Publisher whenever a new MaybeSource is emitted, disposing the previously running MaybeSource, exposing the success items as a Flowable sequence and delaying all errors from all of them until all terminate.

        Backpressure:
        The sources Publisher is consumed in an unbounded manner (requesting Long.MAX_VALUE). The returned Flowable respects the backpressure from the downstream.
        Scheduler:
        switchOnNextDelayError does not operate by default on a particular Scheduler.
        Error handling:
        The returned Flowable collects all errors emitted by either the sources Publisher or any inner MaybeSource and emits them as a CompositeException when all sources terminate. If only one source ever failed, its error is emitted as-is at the end.
        Type Parameters:
        T - the element type of the MaybeSources
        Parameters:
        sources - the Publisher sequence of inner MaybeSources to switch between
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if sources is null
        Since:
        3.0.0
        See Also:
        switchOnNext(Publisher), ReactiveX operators documentation: Switch
      • unsafeCreate

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T> @NonNull Maybe<T> unsafeCreate​(@NonNull
                                                                  @NonNull MaybeSource<@NonNull T> onSubscribe)
        Advanced use only: creates a Maybe instance without any safeguards by using a callback that is called with a MaybeObserver.

        Scheduler:
        unsafeCreate does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the value type
        Parameters:
        onSubscribe - the function that is called with the subscribing MaybeObserver
        Returns:
        the new Maybe instance
        Throws:
        java.lang.IllegalArgumentException - if onSubscribe is a Maybe
        java.lang.NullPointerException - if onSubscribe is null
      • using

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T,​@NonNull D> @NonNull Maybe<T> using​(@NonNull
                                                                            @NonNull Supplier<? extends @NonNull D> resourceSupplier,
                                                                            @NonNull
                                                                            @NonNull Function<? super @NonNull D,​? extends MaybeSource<? extends @NonNull T>> sourceSupplier,
                                                                            @NonNull
                                                                            @NonNull Consumer<? super @NonNull D> resourceCleanup,
                                                                            boolean eager)
        Constructs a Maybe that creates a dependent resource object which is disposed first ({code eager == true}) when the generated MaybeSource terminates or the downstream disposes; or after ({code eager == false}).

        Eager disposal is particularly appropriate for a synchronous Maybe that reuses resources. disposeAction will only be called once per subscription.

        Scheduler:
        using does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the element type of the generated MaybeSource
        D - the type of the resource associated with the output sequence
        Parameters:
        resourceSupplier - the factory function to create a resource object that depends on the Maybe
        sourceSupplier - the factory function to create a MaybeSource
        resourceCleanup - the function that will dispose of the resource
        eager - If true then resource disposal will happen either on a dispose() call before the upstream is disposed or just before the emission of a terminal event (onSuccess, onComplete or onError). If false the resource disposal will happen either on a dispose() call after the upstream is disposed or just after the emission of a terminal event (onSuccess, onComplete or onError).
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if resourceSupplier, sourceSupplier or resourceCleanup is null
        See Also:
        ReactiveX operators documentation: Using
      • zip

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T,​@NonNull R> @NonNull Maybe<R> zip​(@NonNull
                                                                          @NonNull java.lang.Iterable<? extends MaybeSource<? extends @NonNull T>> sources,
                                                                          @NonNull
                                                                          @NonNull Function<? super java.lang.Object[],​? extends @NonNull R> zipper)
        Returns a Maybe that emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an Iterable of other MaybeSources.

        Note on method signature: since Java doesn't allow creating a generic array with new T[], the implementation of this operator has to create an Object[] instead. Unfortunately, a Function<Integer[], R> passed to the method would trigger a ClassCastException.

        This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This also means it is possible some sources may not get subscribed to at all.

        Scheduler:
        zip does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common value type
        R - the zipped result type
        Parameters:
        sources - an Iterable of source MaybeSources
        zipper - a function that, when applied to an item emitted by each of the source MaybeSources, results in an item that will be emitted by the resulting Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if zipper or sources is null
        See Also:
        ReactiveX operators documentation: Zip
      • zip

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public static <@NonNull T1,​@NonNull T2,​@NonNull R> @NonNull Maybe<R> zip​(@NonNull
                                                                                             @NonNull MaybeSource<? extends @NonNull T1> source1,
                                                                                             @NonNull
                                                                                             @NonNull MaybeSource<? extends @NonNull T2> source2,
                                                                                             @NonNull
                                                                                             @NonNull BiFunction<? super @NonNull T1,​? super @NonNull T2,​? extends @NonNull R> zipper)
        Returns a Maybe that emits the results of a specified combiner function applied to combinations of two items emitted, in sequence, by two other MaybeSources.

        This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This also means it is possible some sources may not get subscribed to at all.

        Scheduler:
        zip does not operate by default on a particular Scheduler.
        Type Parameters:
        T1 - the value type of the first source
        T2 - the value type of the second source
        R - the zipped result type
        Parameters:
        source1 - the first source MaybeSource
        source2 - a second source MaybeSource
        zipper - a function that, when applied to an item emitted by each of the source MaybeSources, results in an item that will be emitted by the resulting Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if source1, source2 or zipper is null
        See Also:
        ReactiveX operators documentation: Zip
      • zipArray

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @SafeVarargs
        public static <@NonNull T,​@NonNull R> @NonNull Maybe<R> zipArray​(@NonNull
                                                                               @NonNull Function<? super java.lang.Object[],​? extends @NonNull R> zipper,
                                                                               @NonNull
                                                                               @NonNull MaybeSource<? extends @NonNull T>... sources)
        Returns a Maybe that emits the results of a specified combiner function applied to combinations of items emitted, in sequence, by an array of other MaybeSources.

        Note on method signature: since Java doesn't allow creating a generic array with new T[], the implementation of this operator has to create an Object[] instead. Unfortunately, a Function<Integer[], R> passed to the method would trigger a ClassCastException.

        This operator terminates eagerly if any of the source MaybeSources signal an onError or onComplete. This also means it is possible some sources may not get subscribed to at all.

        Scheduler:
        zipArray does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the common element type
        R - the result type
        Parameters:
        sources - an array of source MaybeSources
        zipper - a function that, when applied to an item emitted by each of the source MaybeSources, results in an item that will be emitted by the resulting Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if sources or zipper is null
        See Also:
        ReactiveX operators documentation: Zip
      • blockingGet

        @CheckReturnValue
        @SchedulerSupport("none")
        @Nullable
        public final T blockingGet()
        Waits in a blocking fashion until the current Maybe signals a success value (which is returned), null if completed or an exception (which is propagated).

        Scheduler:
        blockingGet does not operate by default on a particular Scheduler.
        Error handling:
        If the source signals an error, the operator wraps a checked Exception into RuntimeException and throws that. Otherwise, RuntimeExceptions and Errors are rethrown as they are.
        Returns:
        the success value
      • blockingGet

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final T blockingGet​(@NonNull
                                   @NonNull T defaultValue)
        Waits in a blocking fashion until the current Maybe signals a success value (which is returned), defaultValue if completed or an exception (which is propagated).

        Scheduler:
        blockingGet does not operate by default on a particular Scheduler.
        Error handling:
        If the source signals an error, the operator wraps a checked Exception into RuntimeException and throws that. Otherwise, RuntimeExceptions and Errors are rethrown as they are.
        Parameters:
        defaultValue - the default item to return if this Maybe is empty
        Returns:
        the success value
        Throws:
        java.lang.NullPointerException - if defaultValue is null
      • blockingSubscribe

        @SchedulerSupport("none")
        public final void blockingSubscribe​(@NonNull
                                            @NonNull Consumer<? super @NonNull T> onSuccess,
                                            @NonNull
                                            @NonNull Consumer<? super java.lang.Throwable> onError)
        Subscribes to the current Maybe and calls the appropriate callback on the current thread when it terminates.

        Scheduler:
        blockingSubscribe does not operate by default on a particular Scheduler.
        Error handling:
        If either onSuccess or onError throw, the Throwable is routed to the global error handler via RxJavaPlugins.onError(Throwable). If the current thread is interrupted, the onError consumer is called with an InterruptedException.
        Parameters:
        onSuccess - the Consumer to call if the current Maybe succeeds
        onError - the Consumer to call if the current Maybe signals an error
        Throws:
        java.lang.NullPointerException - if onSuccess or onError is null
        Since:
        3.0.0
        See Also:
        blockingSubscribe(Consumer, Consumer, Action)
      • blockingSubscribe

        @SchedulerSupport("none")
        public final void blockingSubscribe​(@NonNull
                                            @NonNull Consumer<? super @NonNull T> onSuccess,
                                            @NonNull
                                            @NonNull Consumer<? super java.lang.Throwable> onError,
                                            @NonNull
                                            @NonNull Action onComplete)
        Subscribes to the current Maybe and calls the appropriate callback on the current thread when it terminates.

        Scheduler:
        blockingSubscribe does not operate by default on a particular Scheduler.
        Error handling:
        If either onSuccess, onError or onComplete throw, the Throwable is routed to the global error handler via RxJavaPlugins.onError(Throwable). If the current thread is interrupted, the onError consumer is called with an InterruptedException.
        Parameters:
        onSuccess - the Consumer to call if the current Maybe succeeds
        onError - the Consumer to call if the current Maybe signals an error
        onComplete - the Action to call if the current Maybe completes without a value
        Throws:
        java.lang.NullPointerException - if onSuccess, onError or onComplete is null
        Since:
        3.0.0
      • blockingSubscribe

        @SchedulerSupport("none")
        public final void blockingSubscribe​(@NonNull
                                            @NonNull MaybeObserver<? super @NonNull T> observer)
        Subscribes to the current Maybe and calls the appropriate MaybeObserver method on the current thread.

        Scheduler:
        blockingSubscribe does not operate by default on a particular Scheduler.
        Error handling:
        An onError signal is delivered to the MaybeObserver.onError(Throwable) method. If any of the MaybeObserver's methods throw, the RuntimeException is propagated to the caller of this method. If the current thread is interrupted, an InterruptedException is delivered to observer.onError.
        Parameters:
        observer - the MaybeObserver to call methods on the current thread
        Throws:
        java.lang.NullPointerException - if observer is null
        Since:
        3.0.0
      • cache

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> cache()
        Returns a Maybe that subscribes to this Maybe lazily, caches its event and replays it, to all the downstream subscribers.

        The operator subscribes only when the first downstream subscriber subscribes and maintains a single subscription towards this Maybe.

        Note: You sacrifice the ability to dispose the origin when you use the cache.

        Scheduler:
        cache does not operate by default on a particular Scheduler.
        Returns:
        the new Maybe instance
        See Also:
        ReactiveX operators documentation: Replay
      • cast

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull U> @NonNull Maybe<U> cast​(@NonNull
                                                         @NonNull java.lang.Class<? extends @NonNull U> clazz)
        Casts the success value of the current Maybe into the target type or signals a ClassCastException if not compatible.

        Scheduler:
        cast does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the target type
        Parameters:
        clazz - the type token to use for casting the success result from the current Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if clazz is null
      • dematerialize

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull R> @NonNull Maybe<R> dematerialize​(@NonNull
                                                                  @NonNull Function<? super @NonNull T,​@NonNull Notification<@NonNull R>> selector)
        Maps the Notification success value of the current Maybe back into normal onSuccess, onError or onComplete signals.

        The intended use of the selector function is to perform a type-safe identity mapping (see example) on a source that is already of type Notification<T>. The Java language doesn't allow limiting instance methods to a certain generic argument shape, therefore, a function is used to ensure the conversion remains type safe.

        Regular onError or onComplete signals from the current Maybe are passed along to the downstream.

        Scheduler:
        dematerialize does not operate by default on a particular Scheduler.

        Example:

        
         Maybe.just(Notification.createOnNext(1))
         .dematerialize(notification -> notification)
         .test()
         .assertResult(1);
         
        Type Parameters:
        R - the result type
        Parameters:
        selector - the function called with the success item and should return a Notification instance.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if selector is null
        Since:
        3.0.0
        See Also:
        materialize()
      • delay

        @CheckReturnValue
        @SchedulerSupport("io.reactivex:computation")
        @NonNull
        public final @NonNull Maybe<T> delay​(long time,
                                             @NonNull
                                             @NonNull java.util.concurrent.TimeUnit unit,
                                             boolean delayError)
        Returns a Maybe that signals the events emitted by the current Maybe shifted forward in time by a specified delay.

        Scheduler:
        This version of delay operates by default on the computation Scheduler.
        Parameters:
        time - the delay to shift the source by
        unit - the TimeUnit in which time is defined
        delayError - if true, both success and error signals are delayed. if false, only success signals are delayed.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit is null
        Since:
        3.0.0
        See Also:
        ReactiveX operators documentation: Delay, delay(long, TimeUnit, Scheduler, boolean)
      • delay

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Maybe<T> delay​(long time,
                                             @NonNull
                                             @NonNull java.util.concurrent.TimeUnit unit,
                                             @NonNull
                                             @NonNull Scheduler scheduler,
                                             boolean delayError)
        Returns a Maybe that signals the events emitted by the current Maybe shifted forward in time by a specified delay running on the specified Scheduler.

        Scheduler:
        you specify which Scheduler this operator will use.
        Parameters:
        time - the delay to shift the source by
        unit - the TimeUnit in which time is defined
        scheduler - the Scheduler to use for delaying
        delayError - if true, both success and error signals are delayed. if false, only success signals are delayed.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
        Since:
        3.0.0
        See Also:
        ReactiveX operators documentation: Delay
      • delay

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        @BackpressureSupport(UNBOUNDED_IN)
        public final <@NonNull U> @NonNull Maybe<T> delay​(@NonNull
                                                          @NonNull org.reactivestreams.Publisher<@NonNull U> delayIndicator)
        Delays the emission of this Maybe until the given Publisher signals an item or completes.

        Backpressure:
        The delayIndicator is consumed in an unbounded manner but is cancelled after the first item it produces.
        Scheduler:
        This version of delay does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the subscription delay value type (ignored)
        Parameters:
        delayIndicator - the Publisher that gets subscribed to when this Maybe signals an event and that signal is emitted when the Publisher signals an item or completes
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if delayIndicator is null
        See Also:
        ReactiveX operators documentation: Delay
      • delaySubscription

        @BackpressureSupport(UNBOUNDED_IN)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull U> @NonNull Maybe<T> delaySubscription​(@NonNull
                                                                      @NonNull org.reactivestreams.Publisher<@NonNull U> subscriptionIndicator)
        Returns a Maybe that delays the subscription to this Maybe until the other Publisher emits an element or completes normally.

        Backpressure:
        The Publisher source is consumed in an unbounded fashion (without applying backpressure).
        Scheduler:
        This method does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the value type of the other Publisher, irrelevant
        Parameters:
        subscriptionIndicator - the other Publisher that should trigger the subscription to this Publisher.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if subscriptionIndicator is null
      • delaySubscription

        @CheckReturnValue
        @SchedulerSupport("custom")
        @NonNull
        public final @NonNull Maybe<T> delaySubscription​(long time,
                                                         @NonNull
                                                         @NonNull java.util.concurrent.TimeUnit unit,
                                                         @NonNull
                                                         @NonNull Scheduler scheduler)
        Returns a Maybe that delays the subscription to the current Maybe by a given amount of time, both waiting and subscribing on a given Scheduler.

        Scheduler:
        You specify which Scheduler this operator will use.
        Parameters:
        time - the time to delay the subscription
        unit - the time unit of delay
        scheduler - the Scheduler on which the waiting and subscription will happen
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
        See Also:
        ReactiveX operators documentation: Delay
      • doAfterSuccess

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> doAfterSuccess​(@NonNull
                                                      @NonNull Consumer<? super @NonNull T> onAfterSuccess)
        Calls the specified Consumer with the success item after this item has been emitted to the downstream.

        Note that the onAfterSuccess action is shared between subscriptions and as such should be thread-safe.

        Scheduler:
        doAfterSuccess does not operate by default on a particular Scheduler.

        History: 2.0.1 - experimental

        Parameters:
        onAfterSuccess - the Consumer that will be called after emitting an item from upstream to the downstream
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if onAfterSuccess is null
        Since:
        2.1
      • doFinally

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> doFinally​(@NonNull
                                                 @NonNull Action onFinally)
        Calls the specified action after this Maybe signals onSuccess, onError or onComplete or gets disposed by the downstream.

        In case of a race between a terminal event and a dispose call, the provided onFinally action is executed once per subscription.

        Note that the onFinally action is shared between subscriptions and as such should be thread-safe.

        Scheduler:
        doFinally does not operate by default on a particular Scheduler.

        History: 2.0.1 - experimental

        Parameters:
        onFinally - the action called when this Maybe terminates or gets disposed
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if onFinally is null
        Since:
        2.1
      • doOnEvent

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> doOnEvent​(@NonNull
                                                 @NonNull BiConsumer<? super @NonNull T,​? super java.lang.Throwable> onEvent)
        Calls the given onEvent callback with the (success value, null) for an onSuccess, (null, throwable) for an onError or (null, null) for an onComplete signal from this Maybe before delivering said signal to the downstream.

        The exceptions thrown from the callback will override the event so the downstream receives the error instead of the original signal.

        Scheduler:
        doOnEvent does not operate by default on a particular Scheduler.
        Parameters:
        onEvent - the callback to call with the success value or the exception, whichever is not null
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if onEvent is null
      • doOnTerminate

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> doOnTerminate​(@NonNull
                                                     @NonNull Action onTerminate)
        Returns a Maybe instance that calls the given onTerminate callback just before this Maybe completes normally or with an exception.

        This differs from doAfterTerminate in that this happens before the onComplete or onError notification.

        Scheduler:
        doOnTerminate does not operate by default on a particular Scheduler.

        History: 2.2.7 - experimental

        Parameters:
        onTerminate - the action to invoke when the consumer calls onComplete or onError
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if onTerminate is null
        Since:
        3.0.0
        See Also:
        ReactiveX operators documentation: Do, doOnTerminate(Action)
      • lift

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull R> @NonNull Maybe<R> lift​(@NonNull
                                                         @NonNull MaybeOperator<? extends @NonNull R,​? super @NonNull T> lift)
        This method requires advanced knowledge about building operators, please consider other standard composition methods first; Returns a Maybe which, when subscribed to, invokes the apply(MaybeObserver) method of the provided MaybeOperator for each individual downstream Maybe and allows the insertion of a custom operator by accessing the downstream's MaybeObserver during this subscription phase and providing a new MaybeObserver, containing the custom operator's intended business logic, that will be used in the subscription process going further upstream.

        Generally, such a new MaybeObserver will wrap the downstream's MaybeObserver and forwards the onSuccess, onError and onComplete events from the upstream directly or according to the emission pattern the custom operator's business logic requires. In addition, such operator can intercept the flow control calls of dispose and isDisposed that would have traveled upstream and perform additional actions depending on the same business logic requirements.

        Example:

        
         // Step 1: Create the consumer type that will be returned by the MaybeOperator.apply():
         
         public final class CustomMaybeObserver<T> implements MaybeObserver<T>, Disposable {
        
             // The downstream's MaybeObserver that will receive the onXXX events
             final MaybeObserver<? super String> downstream;
        
             // The connection to the upstream source that will call this class' onXXX methods
             Disposable upstream;
        
             // The constructor takes the downstream subscriber and usually any other parameters
             public CustomMaybeObserver(MaybeObserver<? super String> downstream) {
                 this.downstream = downstream;
             }
        
             // In the subscription phase, the upstream sends a Disposable to this class
             // and subsequently this class has to send a Disposable to the downstream.
             // Note that relaying the upstream's Disposable directly is not allowed in RxJava
             @Override
             public void onSubscribe(Disposable d) {
                 if (upstream != null) {
                     d.dispose();
                 } else {
                     upstream = d;
                     downstream.onSubscribe(this);
                 }
             }
        
             // The upstream calls this with the next item and the implementation's
             // responsibility is to emit an item to the downstream based on the intended
             // business logic, or if it can't do so for the particular item,
             // request more from the upstream
             @Override
             public void onSuccess(T item) {
                 String str = item.toString();
                 if (str.length() < 2) {
                     downstream.onSuccess(str);
                 } else {
                     // Maybe is expected to produce one of the onXXX events only
                     downstream.onComplete();
                 }
             }
        
             // Some operators may handle the upstream's error while others
             // could just forward it to the downstream.
             @Override
             public void onError(Throwable throwable) {
                 downstream.onError(throwable);
             }
        
             // When the upstream completes, usually the downstream should complete as well.
             @Override
             public void onComplete() {
                 downstream.onComplete();
             }
        
             // Some operators may use their own resources which should be cleaned up if
             // the downstream disposes the flow before it completed. Operators without
             // resources can simply forward the dispose to the upstream.
             // In some cases, a disposed flag may be set by this method so that other parts
             // of this class may detect the dispose and stop sending events
             // to the downstream.
             @Override
             public void dispose() {
                 upstream.dispose();
             }
        
             // Some operators may simply forward the call to the upstream while others
             // can return the disposed flag set in dispose().
             @Override
             public boolean isDisposed() {
                 return upstream.isDisposed();
             }
         }
        
         // Step 2: Create a class that implements the MaybeOperator interface and
         //         returns the custom consumer type from above in its apply() method.
         //         Such class may define additional parameters to be submitted to
         //         the custom consumer type.
        
         final class CustomMaybeOperator<T> implements MaybeOperator<String> {
             @Override
             public MaybeObserver<? super String> apply(MaybeObserver<? super T> upstream) {
                 return new CustomMaybeObserver<T>(upstream);
             }
         }
        
         // Step 3: Apply the custom operator via lift() in a flow by creating an instance of it
         //         or reusing an existing one.
        
         Maybe.just(5)
         .lift(new CustomMaybeOperator<Integer>())
         .test()
         .assertResult("5");
        
         Maybe.just(15)
         .lift(new CustomMaybeOperator<Integer>())
         .test()
         .assertResult();
         

        Creating custom operators can be complicated and it is recommended one consults the RxJava wiki: Writing operators page about the tools, requirements, rules, considerations and pitfalls of implementing them.

        Note that implementing custom operators via this lift() method adds slightly more overhead by requiring an additional allocation and indirection per assembled flows. Instead, extending the abstract Maybe class and creating a MaybeTransformer with it is recommended.

        Note also that it is not possible to stop the subscription phase in lift() as the apply() method requires a non-null MaybeObserver instance to be returned, which is then unconditionally subscribed to the current Maybe. For example, if the operator decided there is no reason to subscribe to the upstream source because of some optimization possibility or a failure to prepare the operator, it still has to return a MaybeObserver that should immediately dispose the upstream's Disposable in its onSubscribe method. Again, using a MaybeTransformer and extending the Maybe is a better option as subscribeActual(io.reactivex.rxjava3.core.MaybeObserver<? super T>) can decide to not subscribe to its upstream after all.

        Scheduler:
        lift does not operate by default on a particular Scheduler, however, the MaybeOperator may use a Scheduler to support its own asynchronous behavior.
        Type Parameters:
        R - the output value type
        Parameters:
        lift - the MaybeOperator that receives the downstream's MaybeObserver and should return a MaybeObserver with custom behavior to be used as the consumer for the current Maybe.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if lift is null
        See Also:
        RxJava wiki: Writing operators, compose(MaybeTransformer)
      • to

        @CheckReturnValue
        @SchedulerSupport("none")
        public final <R> R to​(@NonNull
                              @NonNull MaybeConverter<@NonNull T,​? extends R> converter)
        Calls the specified converter function during assembly time and returns its resulting value.

        This allows fluent conversion to any other type.

        Scheduler:
        to does not operate by default on a particular Scheduler.

        History: 2.1.7 - experimental

        Type Parameters:
        R - the resulting object type
        Parameters:
        converter - the function that receives the current Maybe instance and returns a value
        Returns:
        the converted value
        Throws:
        java.lang.NullPointerException - if converter is null
        Since:
        2.2
      • toFuture

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull java.util.concurrent.Future<T> toFuture()
        Returns a Future representing the single value emitted by the current Maybe or null if the current Maybe is empty.

        Cancelling the Future will cancel the subscription to the current Maybe.

        Scheduler:
        toFuture does not operate by default on a particular Scheduler.
        Returns:
        the new Future instance
        Since:
        3.0.0
        See Also:
        ReactiveX documentation: To
      • onErrorComplete

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> onErrorComplete()
        Returns a Maybe instance that if this Maybe emits an error, it will emit an onComplete and swallow the throwable.

        Scheduler:
        onErrorComplete does not operate by default on a particular Scheduler.
        Returns:
        the new Maybe instance
      • onErrorComplete

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> onErrorComplete​(@NonNull
                                                       @NonNull Predicate<? super java.lang.Throwable> predicate)
        Returns a Maybe instance that if this Maybe emits an error and the predicate returns true, it will emit an onComplete and swallow the throwable.

        Scheduler:
        onErrorComplete does not operate by default on a particular Scheduler.
        Parameters:
        predicate - the predicate to call when an Throwable is emitted which should return true if the Throwable should be swallowed and replaced with an onComplete.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if predicate is null
      • onErrorResumeNext

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> onErrorResumeNext​(@NonNull
                                                         @NonNull Function<? super java.lang.Throwable,​? extends MaybeSource<? extends @NonNull T>> fallbackSupplier)
        Resumes the flow with a MaybeSource returned for the failure Throwable of the current Maybe by a function instead of signaling the error via onError.

        You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.

        Scheduler:
        onErrorResumeNext does not operate by default on a particular Scheduler.
        Parameters:
        fallbackSupplier - a function that returns a MaybeSource that will take over if the current Maybe encounters an error
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if fallbackSupplier is null
        See Also:
        ReactiveX operators documentation: Catch
      • onErrorReturn

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> onErrorReturn​(@NonNull
                                                     @NonNull Function<? super java.lang.Throwable,​? extends @NonNull T> itemSupplier)
        Ends the flow with a success item returned by a function for the Throwable error signaled by the current Maybe instead of signaling the error via onError.

        You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.

        Scheduler:
        onErrorReturn does not operate by default on a particular Scheduler.
        Parameters:
        itemSupplier - a function that returns a single value that will be emitted as success value the current Maybe signals an onError event
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if itemSupplier is null
        See Also:
        ReactiveX operators documentation: Catch
      • onErrorReturnItem

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> onErrorReturnItem​(@NonNull
                                                         @NonNull T item)
        Ends the flow with the given success item when the current Maybe fails instead of signaling the error via onError.

        You can use this to prevent errors from propagating or to supply fallback data should errors be encountered.

        Scheduler:
        onErrorReturnItem does not operate by default on a particular Scheduler.
        Parameters:
        item - the value that is emitted as onSuccess in case the current Maybe signals an onError
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if item is null
        See Also:
        ReactiveX operators documentation: Catch
      • onTerminateDetach

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> onTerminateDetach()
        Nulls out references to the upstream producer and downstream MaybeObserver if the sequence is terminated or downstream calls dispose().

        Scheduler:
        onTerminateDetach does not operate by default on a particular Scheduler.
        Returns:
        the new Maybe instance the sequence is terminated or downstream calls dispose()
      • repeatWhen

        @BackpressureSupport(FULL)
        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Flowable<T> repeatWhen​(@NonNull
                                                     @NonNull Function<? super Flowable<java.lang.Object>,​? extends org.reactivestreams.Publisher<?>> handler)
        Returns a Flowable that emits the same values as the current Maybe with the exception of an onComplete. An onComplete notification from the source will result in the emission of a void item to the Flowable provided as an argument to the notificationHandler function. If that Publisher calls onComplete or onError then repeatWhen will call onComplete or onError on the child observer. Otherwise, this operator will resubscribe to the current Maybe.

        Backpressure:
        The operator honors downstream backpressure and expects the source Publisher to honor backpressure as well. If this expectation is violated, the operator may throw an IllegalStateException.
        Scheduler:
        repeatWhen does not operate by default on a particular Scheduler.
        Parameters:
        handler - receives a Publisher of notifications with which a user can complete or error, aborting the repeat.
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if handler is null
        See Also:
        ReactiveX operators documentation: Repeat
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> retry​(@NonNull
                                             @NonNull BiPredicate<? super java.lang.Integer,​? super java.lang.Throwable> predicate)
        Returns a Maybe that mirrors the current Maybe, resubscribing to it if it calls onError and the predicate returns true for that specific exception and retry count.

        Scheduler:
        retry does not operate by default on a particular Scheduler.
        Parameters:
        predicate - the predicate that determines if a resubscription may happen in case of a specific exception and retry count
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if predicate is null
        See Also:
        retry(), ReactiveX operators documentation: Retry
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> retry​(long times)
        Returns a Maybe that mirrors the current Maybe, resubscribing to it if it calls onError up to a specified number of retries.

        If the current Maybe calls MaybeObserver.onError(java.lang.Throwable), this operator will resubscribe to the current Maybe for a maximum of count resubscriptions rather than propagating the onError call.

        Scheduler:
        retry does not operate by default on a particular Scheduler.
        Parameters:
        times - the number of times to resubscribe if the current Maybe fails
        Returns:
        the new Maybe instance
        Throws:
        java.lang.IllegalArgumentException - if times is negative
        See Also:
        ReactiveX operators documentation: Retry
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> retry​(long times,
                                             @NonNull
                                             @NonNull Predicate<? super java.lang.Throwable> predicate)
        Retries at most times or until the predicate returns false, whichever happens first.

        Scheduler:
        retry does not operate by default on a particular Scheduler.
        Parameters:
        times - the number of times to resubscribe if the current Maybe fails
        predicate - the predicate called with the failure Throwable and should return true to trigger a retry.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if predicate is null
        java.lang.IllegalArgumentException - if times is negative
      • retry

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> retry​(@NonNull
                                             @NonNull Predicate<? super java.lang.Throwable> predicate)
        Retries the current Maybe if it fails and the predicate returns true.

        Scheduler:
        retry does not operate by default on a particular Scheduler.
        Parameters:
        predicate - the predicate that receives the failure Throwable and should return true to trigger a retry.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if predicate is null
      • retryWhen

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Maybe<T> retryWhen​(@NonNull
                                                 @NonNull Function<? super Flowable<java.lang.Throwable>,​? extends org.reactivestreams.Publisher<?>> handler)
        Returns a Maybe that emits the same values as the current Maybe with the exception of an onError. An onError notification from the source will result in the emission of a Throwable item to the Flowable provided as an argument to the notificationHandler function. If the returned Publisher calls onComplete or onError then retry will call onComplete or onError on the child subscription. Otherwise, this operator will resubscribe to the current Maybe.

        Example: This retries 3 times, each time incrementing the number of seconds it waits.

        
          Maybe.create((MaybeEmitter<? super String> s) -> {
              System.out.println("subscribing");
              s.onError(new RuntimeException("always fails"));
          }, BackpressureStrategy.BUFFER).retryWhen(attempts -> {
              return attempts.zipWith(Publisher.range(1, 3), (n, i) -> i).flatMap(i -> {
                  System.out.println("delay retry by " + i + " second(s)");
                  return Flowable.timer(i, TimeUnit.SECONDS);
              });
          }).blockingForEach(System.out::println);
         
        Output is:
         
         subscribing
         delay retry by 1 second(s)
         subscribing
         delay retry by 2 second(s)
         subscribing
         delay retry by 3 second(s)
         subscribing
          

        Note that the inner Publisher returned by the handler function should signal either onNext, onError or onComplete in response to the received Throwable to indicate the operator should retry or terminate. If the upstream to the operator is asynchronous, signalling onNext followed by onComplete immediately may result in the sequence to be completed immediately. Similarly, if this inner Publisher signals onError or onComplete while the upstream is active, the sequence is terminated with the same signal immediately.

        The following example demonstrates how to retry an asynchronous source with a delay:

        
         Maybe.timer(1, TimeUnit.SECONDS)
             .doOnSubscribe(s -> System.out.println("subscribing"))
             .map(v -> { throw new RuntimeException(); })
             .retryWhen(errors -> {
                 AtomicInteger counter = new AtomicInteger();
                 return errors
                           .takeWhile(e -> counter.getAndIncrement() != 3)
                           .flatMap(e -> {
                               System.out.println("delay retry by " + counter.get() + " second(s)");
                               return Flowable.timer(counter.get(), TimeUnit.SECONDS);
                           });
             })
             .blockingGet();
         
        Scheduler:
        retryWhen does not operate by default on a particular Scheduler.
        Parameters:
        handler - receives a Publisher of notifications with which a user can complete or error, aborting the retry
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if handler is null
        See Also:
        ReactiveX operators documentation: Retry
      • startWith

        @CheckReturnValue
        @NonNull
        @BackpressureSupport(FULL)
        @SchedulerSupport("none")
        public final @NonNull Flowable<T> startWith​(@NonNull
                                                    @NonNull org.reactivestreams.Publisher<@NonNull T> other)
        Returns a Flowable which first delivers the events of the other Publisher then runs the current Maybe.

        Backpressure:
        The returned Flowable honors the backpressure of the downstream consumer and expects the other Publisher to honor it as well.
        Scheduler:
        startWith does not operate by default on a particular Scheduler.
        Parameters:
        other - the other Publisher to run first
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if other is null
        Since:
        3.0.0
      • subscribe

        @SchedulerSupport("none")
        @NonNull
        public final @NonNull Disposable subscribe​(@NonNull
                                                   @NonNull Consumer<? super @NonNull T> onSuccess,
                                                   @NonNull
                                                   @NonNull Consumer<? super java.lang.Throwable> onError,
                                                   @NonNull
                                                   @NonNull Action onComplete,
                                                   @NonNull
                                                   @NonNull DisposableContainer container)
        Wraps the given onXXX callbacks into a Disposable MaybeObserver, adds it to the given DisposableContainer and ensures, that if the upstream terminates or this particular Disposable is disposed, the MaybeObserver is removed from the given composite.

        The MaybeObserver will be removed after the callback for the terminal event has been invoked.

        Scheduler:
        subscribe does not operate by default on a particular Scheduler.
        Parameters:
        onSuccess - the callback for upstream items
        onError - the callback for an upstream error
        onComplete - the callback for an upstream completion without any value or error
        container - the DisposableContainer (such as CompositeDisposable) to add and remove the created Disposable MaybeObserver
        Returns:
        the Disposable that allows disposing the particular subscription.
        Throws:
        java.lang.NullPointerException - if onSuccess, onError, onComplete or container is null
        Since:
        3.1.0
      • subscribeActual

        protected abstract void subscribeActual​(@NonNull
                                                @NonNull MaybeObserver<? super @NonNull T> observer)
        Implement this method in subclasses to handle the incoming MaybeObservers.

        There is no need to call any of the plugin hooks on the current Maybe instance or the MaybeObserver; all hooks and basic safeguards have been applied by subscribe(MaybeObserver) before this method gets called.

        Parameters:
        observer - the MaybeObserver to handle, not null
      • subscribeWith

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final <@NonNull E extends MaybeObserver<? super @NonNull T>> E subscribeWith​(@NonNull E observer)
        Subscribes a given MaybeObserver (subclass) to this Maybe and returns the given MaybeObserver as is.

        Usage example:

        
         Maybe<Integer> source = Maybe.just(1);
         CompositeDisposable composite = new CompositeDisposable();
        
         DisposableMaybeObserver<Integer> ds = new DisposableMaybeObserver<>() {
             // ...
         };
        
         composite.add(source.subscribeWith(ds));
         
        Scheduler:
        subscribeWith does not operate by default on a particular Scheduler.
        Type Parameters:
        E - the type of the MaybeObserver to use and return
        Parameters:
        observer - the MaybeObserver (subclass) to use and return, not null
        Returns:
        the input observer
        Throws:
        java.lang.NullPointerException - if observer is null
      • switchIfEmpty

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Maybe<T> switchIfEmpty​(@NonNull
                                                     @NonNull MaybeSource<? extends @NonNull T> other)
        Returns a Maybe that emits the items emitted by the current Maybe or the items of an alternate MaybeSource if the current Maybe is empty.

        Scheduler:
        switchIfEmpty does not operate by default on a particular Scheduler.
        Parameters:
        other - the alternate MaybeSource to subscribe to if the main does not emit any items
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if other is null
      • switchIfEmpty

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final @NonNull Single<T> switchIfEmpty​(@NonNull
                                                      @NonNull SingleSource<? extends @NonNull T> other)
        Returns a Single that emits the items emitted by the current Maybe or the item of an alternate SingleSource if the current Maybe is empty.

        Scheduler:
        switchIfEmpty does not operate by default on a particular Scheduler.

        History: 2.1.4 - experimental

        Parameters:
        other - the alternate SingleSource to subscribe to if the main does not emit any items
        Returns:
        the new Single instance
        Throws:
        java.lang.NullPointerException - if other is null
        Since:
        2.2
      • timeInterval

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("io.reactivex:computation")
        public final @NonNull Maybe<Timed<T>> timeInterval()
        Measures the time (in milliseconds) between the subscription and success item emission of the current Maybe and signals it as a tuple (Timed) success value.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timeInterval().

        Scheduler:
        timeInterval uses the computation Scheduler for determining the current time upon subscription and upon receiving the success item from the current Maybe.
        Returns:
        the new Maybe instance
        Since:
        3.0.0
      • timeInterval

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Maybe<Timed<T>> timeInterval​(@NonNull
                                                           @NonNull Scheduler scheduler)
        Measures the time (in milliseconds) between the subscription and success item emission of the current Maybe and signals it as a tuple (Timed) success value.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timeInterval(Scheduler).

        Scheduler:
        timeInterval uses the provided Scheduler for determining the current time upon subscription and upon receiving the success item from the current Maybe.
        Parameters:
        scheduler - the Scheduler used for providing the current time
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if scheduler is null
        Since:
        3.0.0
      • timeInterval

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("io.reactivex:computation")
        public final @NonNull Maybe<Timed<T>> timeInterval​(@NonNull
                                                           @NonNull java.util.concurrent.TimeUnit unit)
        Measures the time between the subscription and success item emission of the current Maybe and signals it as a tuple (Timed) success value.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timeInterval(TimeUnit).

        Scheduler:
        timeInterval uses the computation Scheduler for determining the current time upon subscription and upon receiving the success item from the current Maybe.
        Parameters:
        unit - the time unit for measurement
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit is null
        Since:
        3.0.0
      • timeInterval

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Maybe<Timed<T>> timeInterval​(@NonNull
                                                           @NonNull java.util.concurrent.TimeUnit unit,
                                                           @NonNull
                                                           @NonNull Scheduler scheduler)
        Measures the time between the subscription and success item emission of the current Maybe and signals it as a tuple (Timed) success value.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timeInterval(TimeUnit, Scheduler).

        Scheduler:
        timeInterval uses the provided Scheduler for determining the current time upon subscription and upon receiving the success item from the current Maybe.
        Parameters:
        unit - the time unit for measurement
        scheduler - the Scheduler used for providing the current time
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
        Since:
        3.0.0
      • timestamp

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("io.reactivex:computation")
        public final @NonNull Maybe<Timed<T>> timestamp()
        Combines the success value from the current Maybe with the current time (in milliseconds) of its reception, using the computation Scheduler as time source, then signals them as a Timed instance.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timestamp().

        Scheduler:
        timestamp uses the computation Scheduler for determining the current time upon receiving the success item from the current Maybe.
        Returns:
        the new Maybe instance
        Since:
        3.0.0
      • timestamp

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Maybe<Timed<T>> timestamp​(@NonNull
                                                        @NonNull Scheduler scheduler)
        Combines the success value from the current Maybe with the current time (in milliseconds) of its reception, using the given Scheduler as time source, then signals them as a Timed instance.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timestamp(Scheduler).

        Scheduler:
        timestamp uses the provided Scheduler for determining the current time upon receiving the success item from the current Maybe.
        Parameters:
        scheduler - the Scheduler used for providing the current time
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if scheduler is null
        Since:
        3.0.0
      • timestamp

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("io.reactivex:computation")
        public final @NonNull Maybe<Timed<T>> timestamp​(@NonNull
                                                        @NonNull java.util.concurrent.TimeUnit unit)
        Combines the success value from the current Maybe with the current time of its reception, using the computation Scheduler as time source, then signals it as a Timed instance.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timestamp(TimeUnit).

        Scheduler:
        timestamp uses the computation Scheduler, for determining the current time upon receiving the success item from the current Maybe.
        Parameters:
        unit - the time unit for measurement
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit is null
        Since:
        3.0.0
      • timestamp

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Maybe<Timed<T>> timestamp​(@NonNull
                                                        @NonNull java.util.concurrent.TimeUnit unit,
                                                        @NonNull
                                                        @NonNull Scheduler scheduler)
        Combines the success value from the current Maybe with the current time of its reception, using the given Scheduler as time source, then signals it as a Timed instance.

        If the current Maybe is empty or fails, the resulting Maybe will pass along the signals to the downstream. To measure the time to termination, use materialize() and apply Single.timestamp(TimeUnit, Scheduler).

        Scheduler:
        timestamp uses the provided Scheduler, which is used for determining the current time upon receiving the success item from the current Maybe.
        Parameters:
        unit - the time unit for measurement
        scheduler - the Scheduler used for providing the current time
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
        Since:
        3.0.0
      • timeout

        @CheckReturnValue
        @SchedulerSupport("io.reactivex:computation")
        @NonNull
        public final @NonNull Maybe<T> timeout​(long timeout,
                                               @NonNull
                                               @NonNull java.util.concurrent.TimeUnit unit)
        Returns a Maybe that mirrors the current Maybe but applies a timeout policy for each emitted item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resulting Maybe terminates and notifies MaybeObservers of a TimeoutException.

        Scheduler:
        This version of timeout operates by default on the computation Scheduler.
        Parameters:
        timeout - maximum duration between emitted items before a timeout occurs
        unit - the unit of time that applies to the timeout argument.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit is null
        See Also:
        ReactiveX operators documentation: Timeout
      • timeout

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("io.reactivex:computation")
        public final @NonNull Maybe<T> timeout​(long timeout,
                                               @NonNull
                                               @NonNull java.util.concurrent.TimeUnit unit,
                                               @NonNull
                                               @NonNull MaybeSource<? extends @NonNull T> fallback)
        Returns a Maybe that mirrors the current Maybe but applies a timeout policy for each emitted item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the current Maybe is disposed and resulting Maybe begins instead to mirror a fallback MaybeSource.

        Scheduler:
        This version of timeout operates by default on the computation Scheduler.
        Parameters:
        timeout - maximum duration between items before a timeout occurs
        unit - the unit of time that applies to the timeout argument
        fallback - the fallback MaybeSource to use in case of a timeout
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit or fallback is null
        See Also:
        ReactiveX operators documentation: Timeout
      • timeout

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("custom")
        public final @NonNull Maybe<T> timeout​(long timeout,
                                               @NonNull
                                               @NonNull java.util.concurrent.TimeUnit unit,
                                               @NonNull
                                               @NonNull Scheduler scheduler,
                                               @NonNull
                                               @NonNull MaybeSource<? extends @NonNull T> fallback)
        Returns a Maybe that mirrors the current Maybe but applies a timeout policy for each emitted item using a specified Scheduler. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the current Maybe is disposed and resulting Maybe begins instead to mirror a fallback MaybeSource.

        Scheduler:
        You specify which Scheduler this operator will use.
        Parameters:
        timeout - maximum duration between items before a timeout occurs
        unit - the unit of time that applies to the timeout argument
        fallback - the MaybeSource to use as the fallback in case of a timeout
        scheduler - the Scheduler to run the timeout timers on
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if fallback, unit or scheduler is null
        See Also:
        ReactiveX operators documentation: Timeout
      • timeout

        @CheckReturnValue
        @SchedulerSupport("custom")
        @NonNull
        public final @NonNull Maybe<T> timeout​(long timeout,
                                               @NonNull
                                               @NonNull java.util.concurrent.TimeUnit unit,
                                               @NonNull
                                               @NonNull Scheduler scheduler)
        Returns a Maybe that mirrors the current Maybe but applies a timeout policy for each emitted item, where this policy is governed on a specified Scheduler. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resulting Maybe terminates and notifies MaybeObservers of a TimeoutException.

        Scheduler:
        You specify which Scheduler this operator will use.
        Parameters:
        timeout - maximum duration between items before a timeout occurs
        unit - the unit of time that applies to the timeout argument
        scheduler - the Scheduler to run the timeout timers on
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if unit or scheduler is null
        See Also:
        ReactiveX operators documentation: Timeout
      • timeout

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull U> @NonNull Maybe<T> timeout​(@NonNull
                                                            @NonNull MaybeSource<@NonNull U> timeoutIndicator)
        If the current Maybe didn't signal an event before the timeoutIndicator MaybeSource signals, a TimeoutException is signaled instead.

        Scheduler:
        timeout does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the value type of the
        Parameters:
        timeoutIndicator - the MaybeSource that indicates the timeout by signaling onSuccess or onComplete.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if timeoutIndicator is null
      • timeout

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull U> @NonNull Maybe<T> timeout​(@NonNull
                                                            @NonNull MaybeSource<@NonNull U> timeoutIndicator,
                                                            @NonNull
                                                            @NonNull MaybeSource<? extends @NonNull T> fallback)
        If the current Maybe didn't signal an event before the timeoutIndicator MaybeSource signals, the current Maybe is disposed and the fallback MaybeSource subscribed to as a continuation.

        Scheduler:
        timeout does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the value type of the
        Parameters:
        timeoutIndicator - the MaybeSource that indicates the timeout by signaling onSuccess or onComplete.
        fallback - the MaybeSource that is subscribed to if the current Maybe times out
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if timeoutIndicator or fallback is null
      • timeout

        @BackpressureSupport(UNBOUNDED_IN)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull U> @NonNull Maybe<T> timeout​(@NonNull
                                                            @NonNull org.reactivestreams.Publisher<@NonNull U> timeoutIndicator)
        If the current Maybe source didn't signal an event before the timeoutIndicator Publisher signals, a TimeoutException is signaled instead.

        Backpressure:
        The timeoutIndicator Publisher is consumed in an unbounded manner and is cancelled after its first item.
        Scheduler:
        timeout does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the value type of the
        Parameters:
        timeoutIndicator - the Publisher that indicates the timeout by signaling onSuccess or onComplete.
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if timeoutIndicator is null
      • timeout

        @BackpressureSupport(UNBOUNDED_IN)
        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull U> @NonNull Maybe<T> timeout​(@NonNull
                                                            @NonNull org.reactivestreams.Publisher<@NonNull U> timeoutIndicator,
                                                            @NonNull
                                                            @NonNull MaybeSource<? extends @NonNull T> fallback)
        If the current Maybe didn't signal an event before the timeoutIndicator Publisher signals, the current Maybe is disposed and the fallback MaybeSource subscribed to as a continuation.

        Backpressure:
        The timeoutIndicator Publisher is consumed in an unbounded manner and is cancelled after its first item.
        Scheduler:
        timeout does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the value type of the
        Parameters:
        timeoutIndicator - the MaybeSource that indicates the timeout by signaling onSuccess or onComplete
        fallback - the MaybeSource that is subscribed to if the current Maybe times out
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if timeoutIndicator or fallback is null
      • zipWith

        @CheckReturnValue
        @NonNull
        @SchedulerSupport("none")
        public final <@NonNull U,​@NonNull R> @NonNull Maybe<R> zipWith​(@NonNull
                                                                             @NonNull MaybeSource<? extends @NonNull U> other,
                                                                             @NonNull
                                                                             @NonNull BiFunction<? super @NonNull T,​? super @NonNull U,​? extends @NonNull R> zipper)
        Waits until this and the other MaybeSource signal a success value then applies the given BiFunction to those values and emits the BiFunction's resulting value to downstream.

        If either this or the other MaybeSource is empty or signals an error, the resulting Maybe will terminate immediately and dispose the other source.

        Scheduler:
        zipWith does not operate by default on a particular Scheduler.
        Type Parameters:
        U - the type of items emitted by the other MaybeSource
        R - the type of items emitted by the resulting Maybe
        Parameters:
        other - the other MaybeSource
        zipper - a function that combines the pairs of items from the two MaybeSources to generate the items to be emitted by the resulting Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if other or zipper is null
        See Also:
        ReactiveX operators documentation: Zip
      • test

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull TestObserver<T> test​(boolean dispose)
        Creates a TestObserver optionally in cancelled state, then subscribes it to this Maybe.
        Scheduler:
        test does not operate by default on a particular Scheduler.
        Parameters:
        dispose - if true, the TestObserver will be disposed before subscribing to this Maybe.
        Returns:
        the new TestObserver instance
      • fromOptional

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Maybe<@NonNull T> fromOptional​(@NonNull
                                                                           @NonNull java.util.Optional<@NonNull T> optional)
        Converts the existing value of the provided optional into a just(Object) or an empty optional into an empty() Maybe instance.

        Note that the operator takes an already instantiated optional reference and does not by any means create this original optional. If the optional is to be created per consumer upon subscription, use defer(Supplier) around fromOptional:

        
         Maybe.defer(() -> Maybe.fromOptional(createOptional()));
         
        Scheduler:
        fromOptional does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the element type of the optional value
        Parameters:
        optional - the optional value to convert into a Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if optional is null
        Since:
        3.0.0
        See Also:
        just(Object), empty()
      • fromCompletionStage

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public static <@NonNull T> @NonNull Maybe<@NonNull T> fromCompletionStage​(@NonNull
                                                                                  @NonNull java.util.concurrent.CompletionStage<@NonNull T> stage)
        Signals the completion value or error of the given (hot) CompletionStage-based asynchronous calculation.

        Note that the operator takes an already instantiated, running or terminated CompletionStage. If the CompletionStage is to be created per consumer upon subscription, use defer(Supplier) around fromCompletionStage:

        
         Maybe.defer(() -> Maybe.fromCompletionStage(createCompletionStage()));
         

        If the CompletionStage completes with null, the resulting Maybe is completed via onComplete.

        Canceling the flow can't cancel the execution of the CompletionStage because CompletionStage itself doesn't support cancellation. Instead, the operator detaches from the CompletionStage.

        Scheduler:
        fromCompletionStage does not operate by default on a particular Scheduler.
        Type Parameters:
        T - the element type of the CompletionStage
        Parameters:
        stage - the CompletionStage to convert to Maybe and signal its terminal value or error
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if stage is null
        Since:
        3.0.0
      • mapOptional

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final <@NonNull R> @NonNull Maybe<R> mapOptional​(@NonNull
                                                                @NonNull Function<? super @NonNull T,​@NonNull java.util.Optional<? extends @NonNull R>> mapper)
        Maps the upstream success value into an Optional and emits the contained item if not empty.

        Scheduler:
        mapOptional does not operate by default on a particular Scheduler.
        Type Parameters:
        R - the non-null output type
        Parameters:
        mapper - the function that receives the upstream success item and should return a non-empty Optional to emit as the success output or an empty Optional to complete the Maybe
        Returns:
        the new Maybe instance
        Throws:
        java.lang.NullPointerException - if mapper is null
        Since:
        3.0.0
        See Also:
        map(Function), filter(Predicate)
      • toCompletionStage

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull java.util.concurrent.CompletionStage<T> toCompletionStage()
        Signals the upstream success item (or a NoSuchElementException if the upstream is empty) via a CompletionStage.

        The upstream can be canceled by converting the resulting CompletionStage into CompletableFuture via CompletionStage.toCompletableFuture() and calling CompletableFuture.cancel(boolean) on it. The upstream will be also cancelled if the resulting CompletionStage is converted to and completed manually by CompletableFuture.complete(Object) or CompletableFuture.completeExceptionally(Throwable).

        CompletionStages don't have a notion of emptiness and allow nulls, therefore, one can either use toCompletionStage(Object) with null or turn the upstream into a sequence of Optionals and default to Optional.empty():

        
         CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());
         
        Scheduler:
        toCompletionStage does not operate by default on a particular Scheduler.
        Returns:
        the new CompletionStage instance
        Since:
        3.0.0
        See Also:
        toCompletionStage(Object)
      • toCompletionStage

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final @NonNull java.util.concurrent.CompletionStage<T> toCompletionStage​(@Nullable
                                                                                        @NonNull T defaultItem)
        Signals the upstream success item (or the default item if the upstream is empty) via a CompletionStage.

        The upstream can be canceled by converting the resulting CompletionStage into CompletableFuture via CompletionStage.toCompletableFuture() and calling CompletableFuture.cancel(boolean) on it. The upstream will be also cancelled if the resulting CompletionStage is converted to and completed manually by CompletableFuture.complete(Object) or CompletableFuture.completeExceptionally(Throwable).

        CompletionStages don't have a notion of emptiness and allow nulls, therefore, one can either use a defaultItem of null or turn the flow into a sequence of Optionals and default to Optional.empty():

        
         CompletionStage<Optional<T>> stage = source.map(Optional::of).toCompletionStage(Optional.empty());
         
        Scheduler:
        toCompletionStage does not operate by default on a particular Scheduler.
        Parameters:
        defaultItem - the item to signal if the upstream is empty
        Returns:
        the new CompletionStage instance
        Since:
        3.0.0
      • flattenStreamAsFlowable

        @CheckReturnValue
        @SchedulerSupport("none")
        @BackpressureSupport(FULL)
        @NonNull
        public final <@NonNull R> @NonNull Flowable<R> flattenStreamAsFlowable​(@NonNull
                                                                               @NonNull Function<? super @NonNull T,​? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
        Maps the upstream succecss value into a Java Stream and emits its items to the downstream consumer as a Flowable.

        The operator closes the Stream upon cancellation and when it terminates. The exceptions raised when closing a Stream are routed to the global error handler (RxJavaPlugins.onError(Throwable). If a Stream should not be closed, turn it into an Iterable and use flattenAsFlowable(Function):

        
         source.flattenAsFlowable(item -> createStream(item)::iterator);
         

        Primitive streams are not supported and items have to be boxed manually (e.g., via IntStream.boxed()):

        
         source.flattenStreamAsFlowable(item -> IntStream.rangeClosed(1, 10).boxed());
         

        Stream does not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.

        Backpressure:
        The operator honors backpressure from downstream and iterates the given Stream on demand (i.e., when requested).
        Scheduler:
        flattenStreamAsFlowable does not operate by default on a particular Scheduler.
        Type Parameters:
        R - the element type of the Stream and the output Flowable
        Parameters:
        mapper - the function that receives the upstream success item and should return a Stream of values to emit.
        Returns:
        the new Flowable instance
        Throws:
        java.lang.NullPointerException - if mapper is null
        Since:
        3.0.0
        See Also:
        flattenAsFlowable(Function), flattenStreamAsObservable(Function)
      • flattenStreamAsObservable

        @CheckReturnValue
        @SchedulerSupport("none")
        @NonNull
        public final <@NonNull R> @NonNull Observable<R> flattenStreamAsObservable​(@NonNull
                                                                                   @NonNull Function<? super @NonNull T,​? extends java.util.stream.Stream<? extends @NonNull R>> mapper)
        Maps the upstream succecss value into a Java Stream and emits its items to the downstream consumer as an Observable.

        The operator closes the Stream upon cancellation and when it terminates. The exceptions raised when closing a Stream are routed to the global error handler (RxJavaPlugins.onError(Throwable). If a Stream should not be closed, turn it into an Iterable and use flattenAsObservable(Function):

        
         source.flattenAsObservable(item -> createStream(item)::iterator);
         

        Primitive streams are not supported and items have to be boxed manually (e.g., via IntStream.boxed()):

        
         source.flattenStreamAsObservable(item -> IntStream.rangeClosed(1, 10).boxed());
         

        Stream does not support concurrent usage so creating and/or consuming the same instance multiple times from multiple threads can lead to undefined behavior.

        Scheduler:
        flattenStreamAsObservable does not operate by default on a particular Scheduler.
        Type Parameters:
        R - the element type of the Stream and the output Observable
        Parameters:
        mapper - the function that receives the upstream success item and should return a Stream of values to emit.
        Returns:
        the new Observable instance
        Throws:
        java.lang.NullPointerException - if mapper is null
        Since:
        3.0.0
        See Also:
        flattenAsObservable(Function), flattenStreamAsFlowable(Function)