public interface Flow<T> extends FlowOperations<T,Flow<T>>
Mapper
, Predicate
, Worker
and Reducer
objects applied to the flow are).
Flows are lazy: filtering, mapping, and concatenating flows will do so with no, or a
minimum, of evaluation. However, converting a Flow into a List
(or other collection) will
force a realization of the entire flow.
In some cases, a flow may be an infinite, lazily evaluated sequence. Operations that iterate over all elements (such
as FlowOperations.count()
or FlowOperations.reduce(Reducer, Object)
) may become infinite loops.
Using flows allows for a very fluid interface.
Flows are initially created using F.flow(java.util.Collection)
, F.flow(Object...)
or
F.flow(Iterable)
.F.lazy(LazyFunction)
Modifier and Type | Method and Description |
---|---|
<V extends T> |
append(V... values)
Appends any number of type compatible values to the end of this Flow.
|
Flow<T> |
concat(Flow<? extends T> other)
Returns a new Flow with the other Flow's elements appended to this Flow's.
|
Flow<T> |
interleave(Flow<T>... otherFlows)
"Stripes" together a group of flows.
|
<X> Flow<X> |
map(Mapper<T,X> mapper)
Maps a Flow into a new Flow with different type values.
|
<X,Y> Flow<Y> |
map(Mapper2<T,X,Y> mapper,
Flow<? extends X> flow)
Combines two Flows using a two-parameter Mapper.
|
<X> Flow<X> |
mapcat(Mapper<T,Flow<X>> mapper)
Given a
Mapper that maps a T to a Flow<X> , this method will lazily concatenate
all the output flows into a single Flow<X> . |
Flow<T> |
sort()
Sorts this Flow, forming a new Flow.
|
T[] |
toArray(Class<T> type)
Converts the Flow into an array of values (due to type erasure, you have to remind the Flow
about the type).
|
<X> ZippedFlow<T,X> |
zipWith(Flow<X> otherFlow)
Zips this Flow together with another flow to form a Flow of
Tuple s. |
concat, count, drop, each, filter, first, isEmpty, reduce, remove, removeNulls, rest, reverse, sort, take, toList, toSet
forEach, iterator, spliterator
<X> Flow<X> map(Mapper<T,X> mapper)
<X,Y> Flow<Y> map(Mapper2<T,X,Y> mapper, Flow<? extends X> flow)
<X> Flow<X> mapcat(Mapper<T,Flow<X>> mapper)
Mapper
that maps a T to a Flow<X>
, this method will lazily concatenate
all the output flows into a single Flow<X>
.T[] toArray(Class<T> type)
Flow<T> concat(Flow<? extends T> other)
<V extends T> Flow<T> append(V... values)
Flow<T> sort()
ClassCastException
- if type T does not extend Comparable
<X> ZippedFlow<T,X> zipWith(Flow<X> otherFlow)
Tuple
s. The resulting
flow is the length of the shorter of the two input flows. Zipping flows together is a lazy
operation.
The elements of this flow become the Tuple.first value in each Tuple, the elements of the other flow
become the Tuple.second value in each Tuple.X
- type of element stored in the other flowotherFlow
- contains elements to match with elements in this flowFlow<T> interleave(Flow<T>... otherFlows)
5.6.3 - Copyright © 2003-2021 The Apache Software Foundation.