Interface Sequence<T>
- All Known Implementing Classes:
BaseSequence,CombiningSequence,ConcatSequence,ExplodingSequence,FilteredSequence,FrameChannelSequence,LazySequence,MappedSequence,MergeSequence,OperatorSequence,ParallelMergeCombiningSequence,ScanQueryOffsetSequence,SimpleSequence,SkippingSequence,TopNSequence,YieldingSequenceBase
public interface Sequence<T>
A Sequence represents an iterable sequence of elements. Unlike normal Iterators however, it doesn't expose
a way for you to extract values from it, instead you provide it with a worker (an Accumulator) and that defines
what happens with the data.
This inversion of control is in place to allow the Sequence to do resource management. It can enforce that close() methods get called and other resources get cleaned up whenever processing is complete. Without this inversion it is very easy to unintentionally leak resources when iterating over something that is backed by a resource.
Sequences also expose {#see org.apache.druid.java.util.common.guava.Yielder} Yielder objects which allow you to implement a continuation over the Sequence. Yielder do not offer the same guarantees of automatic resource management as the accumulate method, but they are Closeable and will do the proper cleanup when close() is called on them.
-
Method Summary
Modifier and TypeMethodDescription<OutType> OutTypeaccumulate(OutType initValue, Accumulator<OutType, T> accumulator) Accumulate this sequence using the given accumulator.default <R> Sequence<R> default <R> Sequence<R> flatMerge(Function<? super T, ? extends Sequence<? extends R>> mapper, com.google.common.collect.Ordering<? super R> ordering) default voidlimit(long limit) default <U> Sequence<U> skip(long skip) toList()This will materialize the entire sequence.<OutType> Yielder<OutType> toYielder(OutType initValue, YieldingAccumulator<OutType, T> accumulator) Return a Yielder for accumulated sequence.withBaggage(Closeable baggage) withEffect(Runnable effect, Executor effectExecutor)
-
Method Details
-
accumulate
Accumulate this sequence using the given accumulator.- Type Parameters:
OutType- the type of accumulated value.- Parameters:
initValue- the initial value to pass along to start the accumulation.accumulator- the accumulator which is responsible for accumulating input values.- Returns:
- accumulated value.
-
toYielder
Return a Yielder for accumulated sequence.- Type Parameters:
OutType- the type of accumulated value.- Parameters:
initValue- the initial value to pass along to start the accumulation.accumulator- the accumulator which is responsible for accumulating input values.- Returns:
- a Yielder for accumulated sequence.
- See Also:
-
map
-
filter
-
toList
This will materialize the entire sequence. Use at your own risk. -
skip
-
limit
-
flatMap
-
flatMerge
-
forEach
-
withEffect
-
withBaggage
-