Package org.aksw.commons.rx.op
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 typeK- Group key typeV- 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 < 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 ClassesNested classes/interfaces inherited from class org.aksw.commons.util.stream.CollapseRunsOperationBase
CollapseRunsOperationBase.AccumulatorBase -
Field Summary
Fields inherited from class org.aksw.commons.util.stream.CollapseRunsSpecBase
accAdd, accCtor, getGroupKey, groupKeyCompare -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.reactivestreams.Subscriber<? super T>static <T,K, V> FlowableOperatorCollapseRuns<T, K, V> create(CollapseRunsSpec<T, K, V> spec) Deprecated.
-
Constructor Details
-
FlowableOperatorCollapseRuns
-
-
Method Details
-
create
-
apply
-
transformer
Deprecated.Deprecated; Prefer usingFlowable.lift(FlowableOperator)overFlowable.compose(FlowableTransformer)
-