public interface Sequence<T>
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 io.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.
Modifier and Type | Method and Description |
---|---|
<OutType> OutType |
accumulate(OutType initValue,
Accumulator<OutType,T> accumulator)
Accumulate this sequence using the given accumulator.
|
default <R> Sequence<R> |
flatMap(Function<? super T,? extends Sequence<? extends R>> mapper) |
default <R> Sequence<R> |
flatMerge(Function<? super T,? extends Sequence<? extends R>> mapper,
com.google.common.collect.Ordering<? super R> ordering) |
default <U> Sequence<U> |
map(Function<? super T,? extends U> mapper) |
<OutType> Yielder<OutType> |
toYielder(OutType initValue,
YieldingAccumulator<OutType,T> accumulator)
Return an Yielder for accumulated sequence.
|
default Sequence<T> |
withBaggage(Closeable baggage) |
default Sequence<T> |
withEffect(Runnable effect,
Executor effectExecutor) |
<OutType> OutType accumulate(OutType initValue, Accumulator<OutType,T> accumulator)
OutType
- the type of accumulated value.initValue
- the initial value to pass along to start the accumulation.accumulator
- the accumulator which is responsible for accumulating input values.<OutType> Yielder<OutType> toYielder(OutType initValue, YieldingAccumulator<OutType,T> accumulator)
OutType
- the type of accumulated value.initValue
- the initial value to pass along to start the accumulation.accumulator
- the accumulator which is responsible for accumulating input values.Yielder
default <R> Sequence<R> flatMerge(Function<? super T,? extends Sequence<? extends R>> mapper, com.google.common.collect.Ordering<? super R> ordering)
Copyright © 2011–2018. All rights reserved.