Class ObservableTransformers
- java.lang.Object
-
- hu.akarnokd.rxjava3.operators.ObservableTransformers
-
public final class ObservableTransformers extends java.lang.ObjectAdditional operators in the form ofObservableTransformer, useObservable.compose(ObservableTransformer)to apply the operators to an existing sequence.- Since:
- 0.18.2
- See Also:
Observables
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R>
ObservableTransformer<T,R>errorJump(ObservableTransformer<T,R> transformer)Allows an upstream error to jump over an inner transformation and is then reapplied once the inner transformation's returned Flowable terminates.static <T> ObservableTransformer<T,T>filterAsync(Function<? super T,? extends ObservableSource<java.lang.Boolean>> asyncPredicate)Maps each upstream value into a singletrueorfalsevalue provided by a generated ObservableSource for that input value and emits the input value if the inner ObservableSource returnedtrue.static <T> ObservableTransformer<T,T>filterAsync(Function<? super T,? extends ObservableSource<java.lang.Boolean>> asyncPredicate, int bufferSize)Maps each upstream value into a singletrueorfalsevalue provided by a generated ObservableSource for that input value and emits the input value if the inner ObservableSource returnedtrue.static <T,R>
@NonNull ObservableTransformer<T,R>flatMapDrop(Function<? super T,? extends ObservableSource<? extends R>> mapper)FlatMap only oneObservableSourceat a time and ignore upstream values until it terminates.static <T,R>
@NonNull ObservableTransformer<T,R>flatMapLatest(Function<? super T,? extends ObservableSource<? extends R>> mapper)FlatMap only oneObservableSourceat a time and keep the latest upstream value until it terminates and resume with theObservableSourcemapped for that latest upstream value.static <T> @NonNull ObservableTransformer<T,java.lang.Long>indexOf(@NonNull Predicate<? super T> predicate)Returns the first index of an element that matches a predicate or -1L if no elements match.static <T,R>
ObservableTransformer<T,R>mapAsync(Function<? super T,? extends ObservableSource<? extends R>> mapper)Maps each upstream value into a single value provided by a generated ObservableSource for that input value, which is then emitted to the downstream.static <T,R>
ObservableTransformer<T,R>mapAsync(Function<? super T,? extends ObservableSource<? extends R>> mapper, int capacityHint)Maps each upstream value into a single value provided by a generated ObservableSource for that input value, which is then emitted to the downstream.static <T,U,R>
ObservableTransformer<T,R>mapAsync(Function<? super T,? extends ObservableSource<? extends U>> mapper, BiFunction<? super T,? super U,? extends R> combiner)Maps each upstream value into a single value provided by a generated ObservableSource for that input value and combines the original and generated single value into a final result item to be emitted to downstream.static <T,U,R>
ObservableTransformer<T,R>mapAsync(Function<? super T,? extends ObservableSource<? extends U>> mapper, BiFunction<? super T,? super U,? extends R> combiner, int capacityHint)Maps each upstream value into a single value provided by a generated ObservableSource for that input value and combines the original and generated single value into a final result item to be emitted to downstream.static <T> @NonNull ObservableTransformer<T,T>observeOnDrop(@NonNull Scheduler scheduler)Schedules the event emission on aSchedulerand drops upstream values while theonNextwith the current item is executing on that scheduler.static <T> @NonNull ObservableTransformer<T,T>observeOnLatest(@NonNull Scheduler scheduler)Schedules the event emission on aSchedulerand keeps the latest upstream item while the downstream'sonNextis executing so that it will resume with that latest value.static <T> ObservableTransformer<T,T>valve(ObservableSource<java.lang.Boolean> other)Relays values until the other ObservableSource signals false and resumes if the other ObservableSource signals true again, like closing and opening a valve and not losing any items from the main source.static <T> ObservableTransformer<T,T>valve(ObservableSource<java.lang.Boolean> other, boolean defaultOpen)Relays values until the other ObservableSource signals false and resumes if the other ObservableSource signals true again, like closing and opening a valve and not losing any items from the main source and starts with the specified valve state.static <T> ObservableTransformer<T,T>valve(ObservableSource<java.lang.Boolean> other, boolean defaultOpen, int bufferSize)Relays values until the other ObservableSource signals false and resumes if the other ObservableSource signals true again, like closing and opening a valve and not losing any items from the main source and starts with the specified valve state and the specified buffer size hint.
-
-
-
Method Detail
-
indexOf
@SchedulerSupport("none") @CheckReturnValue @NonNull public static <T> @NonNull ObservableTransformer<T,java.lang.Long> indexOf(@NonNull @NonNull Predicate<? super T> predicate)
Returns the first index of an element that matches a predicate or -1L if no elements match.- Type Parameters:
T- the upstream element type- Parameters:
predicate- the predicate called to test each item, returning true will stop the sequence and return the current item index- Returns:
- the new ObservableTransformer instance
- Since:
- 0.18.2
-
observeOnDrop
@SchedulerSupport("custom") @CheckReturnValue @NonNull public static <T> @NonNull ObservableTransformer<T,T> observeOnDrop(@NonNull @NonNull Scheduler scheduler)
Schedules the event emission on aSchedulerand drops upstream values while theonNextwith the current item is executing on that scheduler.Errors are delayed until all items that weren't dropped have been delivered.
- Type Parameters:
T- the element type- Parameters:
scheduler- the scheduler to use for emitting events on- Returns:
- the new ObservableTransformer instance
- See Also:
observeOnLatest(Scheduler)
-
observeOnLatest
@SchedulerSupport("custom") @CheckReturnValue @NonNull public static <T> @NonNull ObservableTransformer<T,T> observeOnLatest(@NonNull @NonNull Scheduler scheduler)
Schedules the event emission on aSchedulerand keeps the latest upstream item while the downstream'sonNextis executing so that it will resume with that latest value.Errors are delayed until the very last item has been delivered.
- Type Parameters:
T- the element type- Parameters:
scheduler- the scheduler to use for emitting events on- Returns:
- the new ObservableTransformer instance
- See Also:
observeOnLatest(Scheduler)
-
flatMapDrop
@SchedulerSupport("none") @CheckReturnValue @NonNull public static <T,R> @NonNull ObservableTransformer<T,R> flatMapDrop(Function<? super T,? extends ObservableSource<? extends R>> mapper)
FlatMap only oneObservableSourceat a time and ignore upstream values until it terminates.Errors are delayed until both the upstream and the active inner
ObservableSourceterminate.- Type Parameters:
T- the upstream value typeR- the output type- Parameters:
mapper- the function that takes an upstream item and returns aObservableSourceto be run exclusively until it finishes- Returns:
- the new ObservableTransformer instance
- Since:
- 0.19.0
-
flatMapLatest
@SchedulerSupport("none") @CheckReturnValue @NonNull public static <T,R> @NonNull ObservableTransformer<T,R> flatMapLatest(Function<? super T,? extends ObservableSource<? extends R>> mapper)
FlatMap only oneObservableSourceat a time and keep the latest upstream value until it terminates and resume with theObservableSourcemapped for that latest upstream value.Errors are delayed until both the upstream and the active inner
ObservableSourceterminate.- Type Parameters:
T- the upstream value typeR- the output type- Parameters:
mapper- the function that takes an upstream item and returns aObservableSourceto be run exclusively until it finishes- Returns:
- the new ObservableTransformer instance
- Since:
- 0.19.0
-
errorJump
public static <T,R> ObservableTransformer<T,R> errorJump(ObservableTransformer<T,R> transformer)
Allows an upstream error to jump over an inner transformation and is then reapplied once the inner transformation's returned Flowable terminates.- Type Parameters:
T- the upstream value typeR- the downstream value type- Parameters:
transformer- the transformation applied to the flow on a per-Subscriber basis- Returns:
- the new FlowableTransformer instance
- Since:
- 0.19.1
-
valve
@SchedulerSupport("none") public static <T> ObservableTransformer<T,T> valve(ObservableSource<java.lang.Boolean> other)
Relays values until the other ObservableSource signals false and resumes if the other ObservableSource signals true again, like closing and opening a valve and not losing any items from the main source.Properties:
- The operator starts with an open valve.
- If the other ObservableSource completes, the sequence terminates with an
IllegalStateException. - The operator doesn't run on any particular
Scheduler. - The operator uses an internal unbounded buffer
of size
Flowable.bufferSize()to hold onto values if the valve is closed.
- Type Parameters:
T- the value type of the main source- Parameters:
other- the other source- Returns:
- the new ObservableTransformer instance
- Throws:
java.lang.NullPointerException- ifotheris null- Since:
- 0.20.2
-
valve
@SchedulerSupport("none") public static <T> ObservableTransformer<T,T> valve(ObservableSource<java.lang.Boolean> other, boolean defaultOpen)
Relays values until the other ObservableSource signals false and resumes if the other ObservableSource signals true again, like closing and opening a valve and not losing any items from the main source and starts with the specified valve state.Properties:
- If the other ObservableSource completes, the sequence terminates with an
IllegalStateException. - The operator doesn't run on any particular
Scheduler. - The operator uses an internal unbounded buffer
of size
Flowable.bufferSize()to hold onto values if the valve is closed.
- Type Parameters:
T- the value type of the main source- Parameters:
other- the other sourcedefaultOpen- should the valve start as open?- Returns:
- the new ObservableTransformer instance
- Throws:
java.lang.NullPointerException- ifotheris null- Since:
- 0.20.2
- If the other ObservableSource completes, the sequence terminates with an
-
valve
@SchedulerSupport("none") public static <T> ObservableTransformer<T,T> valve(ObservableSource<java.lang.Boolean> other, boolean defaultOpen, int bufferSize)
Relays values until the other ObservableSource signals false and resumes if the other ObservableSource signals true again, like closing and opening a valve and not losing any items from the main source and starts with the specified valve state and the specified buffer size hint.Properties:
- If the other ObservableSource completes, the sequence terminates with an
IllegalStateException. - The operator doesn't run on any particular
Scheduler.
- Type Parameters:
T- the value type of the main source- Parameters:
other- the other sourcedefaultOpen- should the valve start as open?bufferSize- the buffer size hint (the chunk size of the underlying unbounded buffer)- Returns:
- the new ObservableTransformer instance
- Throws:
java.lang.IllegalArgumentException- if bufferSize <= 0java.lang.NullPointerException- ifotheris null- Since:
- 0.20.2
- If the other ObservableSource completes, the sequence terminates with an
-
mapAsync
public static <T,R> ObservableTransformer<T,R> mapAsync(Function<? super T,? extends ObservableSource<? extends R>> mapper)
Maps each upstream value into a single value provided by a generated ObservableSource for that input value, which is then emitted to the downstream.Only the first item emitted by the inner ObservableSource are considered. If the inner ObservableSource is empty, no resulting item is generated for that input value.
The inner ObservableSources are consumed in order and one at a time.
- Type Parameters:
T- the input value typeR- the result value type- Parameters:
mapper- the function that receives the upstream value and returns a ObservableSource that should emit a single value to be emitted.- Returns:
- the new ObservableTransformer instance
- Since:
- 0.20.4
-
mapAsync
public static <T,R> ObservableTransformer<T,R> mapAsync(Function<? super T,? extends ObservableSource<? extends R>> mapper, int capacityHint)
Maps each upstream value into a single value provided by a generated ObservableSource for that input value, which is then emitted to the downstream.Only the first item emitted by the inner ObservableSource are considered. If the inner ObservableSource is empty, no resulting item is generated for that input value.
The inner ObservableSources are consumed in order and one at a time.
- Type Parameters:
T- the input value typeR- the result value type- Parameters:
mapper- the function that receives the upstream value and returns a ObservableSource that should emit a single value to be emitted.capacityHint- the number of items expected from the upstream to be buffered while each inner ObservableSource is executing.- Returns:
- the new ObservableTransformer instance
- Since:
- 0.20.4
-
mapAsync
public static <T,U,R> ObservableTransformer<T,R> mapAsync(Function<? super T,? extends ObservableSource<? extends U>> mapper, BiFunction<? super T,? super U,? extends R> combiner)
Maps each upstream value into a single value provided by a generated ObservableSource for that input value and combines the original and generated single value into a final result item to be emitted to downstream.Only the first item emitted by the inner ObservableSource are considered. If the inner ObservableSource is empty, no resulting item is generated for that input value.
The inner ObservableSources are consumed in order and one at a time.
- Type Parameters:
T- the input value typeU- the intermediate value typeR- the result value type- Parameters:
mapper- the function that receives the upstream value and returns a ObservableSource that should emit a single value to be emitted.combiner- the bi-function that receives the original upstream value and the single value emitted by the ObservableSource and returns a result value to be emitted to downstream.- Returns:
- the new ObservableTransformer instance
- Since:
- 0.20.4
-
mapAsync
public static <T,U,R> ObservableTransformer<T,R> mapAsync(Function<? super T,? extends ObservableSource<? extends U>> mapper, BiFunction<? super T,? super U,? extends R> combiner, int capacityHint)
Maps each upstream value into a single value provided by a generated ObservableSource for that input value and combines the original and generated single value into a final result item to be emitted to downstream.Only the first item emitted by the inner ObservableSource are considered. If the inner ObservableSource is empty, no resulting item is generated for that input value.
The inner ObservableSources are consumed in order and one at a time.
- Type Parameters:
T- the input value typeU- the intermediate value typeR- the result value type- Parameters:
mapper- the function that receives the upstream value and returns a ObservableSource that should emit a single value to be emitted.combiner- the bi-function that receives the original upstream value and the single value emitted by the ObservableSource and returns a result value to be emitted to downstream.capacityHint- the number of items expected from the upstream to be buffered while each inner ObservableSource is executing.- Returns:
- the new ObservableTransformer instance
- Since:
- 0.20.4
-
filterAsync
public static <T> ObservableTransformer<T,T> filterAsync(Function<? super T,? extends ObservableSource<java.lang.Boolean>> asyncPredicate)
Maps each upstream value into a singletrueorfalsevalue provided by a generated ObservableSource for that input value and emits the input value if the inner ObservableSource returnedtrue.Only the first item emitted by the inner ObservableSource's are considered. If the inner ObservableSource is empty, no resulting item is generated for that input value.
The inner ObservableSources are consumed in order and one at a time.
- Type Parameters:
T- the input and output value type- Parameters:
asyncPredicate- the function that receives the upstream value and returns a ObservableSource that should emit a single true to indicate the original value should pass.- Returns:
- the new ObservableTransformer instance
- Since:
- 0.20.4
-
filterAsync
public static <T> ObservableTransformer<T,T> filterAsync(Function<? super T,? extends ObservableSource<java.lang.Boolean>> asyncPredicate, int bufferSize)
Maps each upstream value into a singletrueorfalsevalue provided by a generated ObservableSource for that input value and emits the input value if the inner ObservableSource returnedtrue.Only the first item emitted by the inner ObservableSource's are considered. If the inner ObservableSource is empty, no resulting item is generated for that input value.
The inner ObservableSources are consumed in order and one at a time.
- Type Parameters:
T- the input and output value type- Parameters:
asyncPredicate- the function that receives the upstream value and returns a ObservableSource that should emit a single true to indicate the original value should pass.bufferSize- the internal buffer size and prefetch amount to buffer items from upstream until their turn comes up- Returns:
- the new ObservableTransformer instance
- Since:
- 0.20.4
-
-