Class ScalarXMapZHelper


  • final class ScalarXMapZHelper
    extends java.lang.Object
    Utility class to extract a value from a scalar source reactive type, map it to a 0-1 type then subscribe the output type's consumer to it, saving on the overhead of the regular subscription channel.

    History: 2.1.11 - experimental

    Since:
    2.2
    • Constructor Detail

      • ScalarXMapZHelper

        private ScalarXMapZHelper()
    • Method Detail

      • tryAsCompletable

        static <T> boolean tryAsCompletable​(java.lang.Object source,
                                            Function<? super T,​? extends CompletableSource> mapper,
                                            CompletableObserver observer)
        Try subscribing to a CompletableSource mapped from a scalar source (which implements Supplier).
        Type Parameters:
        T - the upstream value type
        Parameters:
        source - the source reactive type (Flowable or Observable) possibly implementing Supplier.
        mapper - the function that turns the scalar upstream value into a CompletableSource
        observer - the consumer to subscribe to the mapped CompletableSource
        Returns:
        true if a subscription did happen and the regular path should be skipped
      • tryAsMaybe

        static <T,​R> boolean tryAsMaybe​(java.lang.Object source,
                                              Function<? super T,​? extends MaybeSource<? extends R>> mapper,
                                              Observer<? super R> observer)
        Try subscribing to a MaybeSource mapped from a scalar source (which implements Supplier).
        Type Parameters:
        T - the upstream value type
        R - the downstream value type
        Parameters:
        source - the source reactive type (Flowable or Observable) possibly implementing Supplier.
        mapper - the function that turns the scalar upstream value into a MaybeSource
        observer - the consumer to subscribe to the mapped MaybeSource
        Returns:
        true if a subscription did happen and the regular path should be skipped
      • tryAsSingle

        static <T,​R> boolean tryAsSingle​(java.lang.Object source,
                                               Function<? super T,​? extends SingleSource<? extends R>> mapper,
                                               Observer<? super R> observer)
        Try subscribing to a SingleSource mapped from a scalar source (which implements Supplier).
        Type Parameters:
        T - the upstream value type
        R - the downstream value type
        Parameters:
        source - the source reactive type (Flowable or Observable) possibly implementing Supplier.
        mapper - the function that turns the scalar upstream value into a SingleSource
        observer - the consumer to subscribe to the mapped SingleSource
        Returns:
        true if a subscription did happen and the regular path should be skipped