Package hu.akarnokd.rxjava3.expr
Class StatementObservable
- java.lang.Object
-
- hu.akarnokd.rxjava3.expr.StatementObservable
-
public final class StatementObservable extends java.lang.ObjectImperative statements expressed as Observable operators.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Observable<T>doWhile(ObservableSource<? extends T> source, BooleanSupplier postCondition)Return an Observable that re-emits the emissions from the source Observable, and then re-subscribes to the source long as a condition is true.static <R> Observable<R>ifThen(BooleanSupplier condition, ObservableSource<? extends R> then)Return an Observable that emits the emissions from a specified Observable if a condition evaluates to true, otherwise return an empty Observable.static <R> Observable<R>ifThen(BooleanSupplier condition, ObservableSource<? extends R> then, Observable<? extends R> orElse)Return an Observable that emits the emissions from one specified Observable if a condition evaluates to true, or from another specified Observable otherwise.static <R> Observable<R>ifThen(BooleanSupplier condition, ObservableSource<? extends R> then, Scheduler scheduler)Return an Observable that emits the emissions from a specified Observable if a condition evaluates to true, otherwise return an empty Observable that runs on a specified Scheduler.static <K,R>
Observable<R>switchCase(Supplier<? extends K> caseSelector, java.util.Map<? super K,? extends ObservableSource<? extends R>> mapOfCases)Return a particular one of several possible Observables based on a case selector.static <K,R>
Observable<R>switchCase(Supplier<? extends K> caseSelector, java.util.Map<? super K,? extends ObservableSource<? extends R>> mapOfCases, ObservableSource<? extends R> defaultCase)Return a particular one of several possible Observables based on a case selector, or a default Observable if the case selector does not map to a particular one.static <K,R>
Observable<R>switchCase(Supplier<? extends K> caseSelector, java.util.Map<? super K,? extends ObservableSource<? extends R>> mapOfCases, Scheduler scheduler)Return a particular one of several possible Observables based on a case selector and run it on the designated scheduler.static <T> Observable<T>whileDo(ObservableSource<? extends T> source, BooleanSupplier preCondition)Return an Observable that re-emits the emissions from the source Observable as long as the condition is true before the first or subsequent subscribe() calls.
-
-
-
Method Detail
-
switchCase
public static <K,R> Observable<R> switchCase(Supplier<? extends K> caseSelector, java.util.Map<? super K,? extends ObservableSource<? extends R>> mapOfCases)
Return a particular one of several possible Observables based on a case selector.
- Type Parameters:
K- the case key typeR- the result value type- Parameters:
caseSelector- the function that produces a case key when an Observer subscribesmapOfCases- a map that maps a case key to an Observable- Returns:
- a particular Observable chosen by key from the map of Observables, or an empty Observable if no Observable matches the key
-
switchCase
public static <K,R> Observable<R> switchCase(Supplier<? extends K> caseSelector, java.util.Map<? super K,? extends ObservableSource<? extends R>> mapOfCases, Scheduler scheduler)
Return a particular one of several possible Observables based on a case selector and run it on the designated scheduler.
- Type Parameters:
K- the case key typeR- the result value type- Parameters:
caseSelector- the function that produces a case key when an Observer subscribesmapOfCases- a map that maps a case key to an Observablescheduler- the scheduler where the empty observable is observed- Returns:
- a particular Observable chosen by key from the map of Observables, or an empty Observable if no Observable matches the key, but one that runs on the designated scheduler in either case
-
switchCase
public static <K,R> Observable<R> switchCase(Supplier<? extends K> caseSelector, java.util.Map<? super K,? extends ObservableSource<? extends R>> mapOfCases, ObservableSource<? extends R> defaultCase)
Return a particular one of several possible Observables based on a case selector, or a default Observable if the case selector does not map to a particular one.
- Type Parameters:
K- the case key typeR- the result value type- Parameters:
caseSelector- the function that produces a case key when an Observer subscribesmapOfCases- a map that maps a case key to an ObservabledefaultCase- the default Observable if themapOfCasesdoesn't contain a value for the key returned by thecaseSelector- Returns:
- a particular Observable chosen by key from the map of Observables, or the default case if no Observable matches the key
-
doWhile
public static <T> Observable<T> doWhile(ObservableSource<? extends T> source, BooleanSupplier postCondition)
Return an Observable that re-emits the emissions from the source Observable, and then re-subscribes to the source long as a condition is true.
- Type Parameters:
T- the value type- Parameters:
source- the source Observable to work withpostCondition- the post condition to test after the source Observable completes- Returns:
- an Observable that replays the emissions from the source Observable, and then continues to replay them so long as the post condition is true
-
whileDo
public static <T> Observable<T> whileDo(ObservableSource<? extends T> source, BooleanSupplier preCondition)
Return an Observable that re-emits the emissions from the source Observable as long as the condition is true before the first or subsequent subscribe() calls.
- Type Parameters:
T- the value type- Parameters:
source- the source Observable to work withpreCondition- the condition to evaluate before subscribing to or replaying the source Observable- Returns:
- an Observable that replays the emissions from the source
Observable so long as
preConditionis true
-
ifThen
public static <R> Observable<R> ifThen(BooleanSupplier condition, ObservableSource<? extends R> then)
Return an Observable that emits the emissions from a specified Observable if a condition evaluates to true, otherwise return an empty Observable.
- Type Parameters:
R- the result value type- Parameters:
condition- the condition that decides whether to emit the emissions from thethenObservablethen- the Observable sequence to emit to ifconditionistrue- Returns:
- an Observable that mimics the
thenObservable if theconditionfunction evaluates to true, or an empty Observable otherwise
-
ifThen
public static <R> Observable<R> ifThen(BooleanSupplier condition, ObservableSource<? extends R> then, Scheduler scheduler)
Return an Observable that emits the emissions from a specified Observable if a condition evaluates to true, otherwise return an empty Observable that runs on a specified Scheduler.
- Type Parameters:
R- the result value type- Parameters:
condition- the condition that decides whether to emit the emissions from thethenObservablethen- the Observable sequence to emit to ifconditionistruescheduler- the Scheduler on which the empty Observable runs if the in case the condition returns false- Returns:
- an Observable that mimics the
thenObservable if theconditionfunction evaluates to true, or an empty Observable running on the specified Scheduler otherwise
-
ifThen
public static <R> Observable<R> ifThen(BooleanSupplier condition, ObservableSource<? extends R> then, Observable<? extends R> orElse)
Return an Observable that emits the emissions from one specified Observable if a condition evaluates to true, or from another specified Observable otherwise.
- Type Parameters:
R- the result value type- Parameters:
condition- the condition that decides which Observable to emit the emissions fromthen- the Observable sequence to emit to ifconditionistrueorElse- the Observable sequence to emit to ifconditionisfalse- Returns:
- an Observable that mimics either the
thenororElseObservables depending on a condition function
-
-