Class FlowableOperatorCollapseRuns<T,K,V>

Type Parameters:
T - Item type
K - Group key type
V - Accumulator type
All Implemented Interfaces:
io.reactivex.rxjava3.core.FlowableOperator<Map.Entry<K,V>, T>

public final class FlowableOperatorCollapseRuns<T,K,V> extends CollapseRunsOperationBase<T,K,V> implements io.reactivex.rxjava3.core.FlowableOperator<Map.Entry<K,V>, T>
Sequential group by; somewhat similar to .toListWhile() but with dedicated support for group keys and accumulators The constructor lambda for accumulators receives the count of so far created accumulators (starting with 0) and the group key. The count can be used to 'skip' accumulation of a certain number of groups. The accumulator constructor function can be null - in which case the accAdd lambda is not invoked. For each group key with a null accumulator a pair (groupKey, null) is emitted.
long skipCount = 5;
flow
  .lift(FlowableOperatorCollapseRuns.create(
      item -> groupKeyOf(item),
      (accNum, groupKey) -> accNum invalid input: '<' skipCount ? null : new RealAcc(),
      (acc, item) -> acc.add(item))
  .skip(skipCount)
  .map(Entry::getValue)
The items' group keys are expected to arrive in order, hence only a single accumulator is active at a time.
Flowable<Entry<Integer, List<Integer>>> list = Flowable
    .range(0, 10)
    .map(i -> Maps.immutableEntry((int)(i / 3), i))
    .lift(FlowableOperatorSequentialGroupBy.<Entry<Integer, Integer>, Integer, List<Integer>>create(Entry::getKey, ArrayList::new, (acc, e) -> acc.add(e.getValue())));

Author:
raven
  • Constructor Details

    • FlowableOperatorCollapseRuns

      public FlowableOperatorCollapseRuns(CollapseRunsSpec<T,K,V> other)
  • Method Details

    • create

      public static <T,K,V> FlowableOperatorCollapseRuns<T,K,V> create(CollapseRunsSpec<T,K,V> spec)
    • apply

      public org.reactivestreams.Subscriber<? super T> apply(org.reactivestreams.Subscriber<? super Map.Entry<K,V>> downstream) throws Exception
      Specified by:
      apply in interface io.reactivex.rxjava3.core.FlowableOperator<T,K>
      Throws:
      Exception
    • transformer

      @Deprecated public io.reactivex.rxjava3.core.FlowableTransformer<T, Map.Entry<K,V>> transformer()
      Deprecated.
      Deprecated; Prefer using Flowable.lift(FlowableOperator) over Flowable.compose(FlowableTransformer)