Class FlowableOperatorCollapseRuns<T,K,V>

java.lang.Object
org.aksw.commons.util.stream.CollapseRunsSpecBase<T,K,V>
org.aksw.commons.util.stream.CollapseRunsOperationBase<T,K,V>
org.aksw.commons.rx.op.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 org.aksw.commons.util.stream.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
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
     

    Nested classes/interfaces inherited from class org.aksw.commons.util.stream.CollapseRunsOperationBase

    org.aksw.commons.util.stream.CollapseRunsOperationBase.AccumulatorBase
  • Field Summary

    Fields inherited from class org.aksw.commons.util.stream.CollapseRunsSpecBase

    accAdd, accCtor, getGroupKey, groupKeyCompare
  • Constructor Summary

    Constructors
    Constructor
    Description
    FlowableOperatorCollapseRuns(org.aksw.commons.util.stream.CollapseRunsSpec<T,K,V> other)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.reactivestreams.Subscriber<? super T>
    apply(org.reactivestreams.Subscriber<? super Map.Entry<K,V>> downstream)
     
    static <T, K, V> FlowableOperatorCollapseRuns<T,K,V>
    create(org.aksw.commons.util.stream.CollapseRunsSpec<T,K,V> spec)
     
    io.reactivex.rxjava3.core.FlowableTransformer<T,Map.Entry<K,V>>
    Deprecated.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • FlowableOperatorCollapseRuns

      public FlowableOperatorCollapseRuns(org.aksw.commons.util.stream.CollapseRunsSpec<T,K,V> other)
  • Method Details

    • create

      public static <T, K, V> FlowableOperatorCollapseRuns<T,K,V> create(org.aksw.commons.util.stream.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)