|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Flow<T>
A Flow is a a functional interface for working with an ordered collection of values.
A given Flow contains only values of a particular type. Standard operations allow for
filtering the Flow, or appending values to the Flow. Since Flows are immutable, all operations
on Flows return new immutable Flows. Flows are thread safe (to the extent that the Mappers, Predicate
s, Workers and Reducers 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 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 values (such as
count() or 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) or F.flow(Object...).
F.lazy(LazyFunction)| Method Summary | ||
|---|---|---|
|
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> |
concat(java.util.List<? extends T> list)
Returns a new Flow with the values in the list appended to this Flow. |
|
int |
count()
Returns the number of values in the Flow. |
|
Flow<T> |
drop(int length)
Returns a new Flow with the first values omitted. |
|
Flow<T> |
each(Worker<? super T> worker)
Applies the worker to each value in the Flow, then returns the flow for further behaviors. |
|
Flow<T> |
filter(Predicate<? super T> predicate)
Filters values, keeping only values where the predicate is true, returning a new Flow with just the retained values. |
|
T |
first()
Returns the first value in the Flow. |
|
boolean |
isEmpty()
Returns true if the Flow contains no values. |
|
|
map(Mapper<T,X> mapper)
Maps a Flow into a new Flow with different type values. |
|
|
map(Mapper2<T,X,Y> mapper,
Flow<? extends X> flow)
Combines two Flows using a two-parameter Mapper. |
|
|
mapcat(Mapper<T,Flow<X>> mapper)
Given a Mapper that maps a T to a Flow |
|
|
reduce(Reducer<A,T> reducer,
A initial)
Applies a Reducer to the values of the Flow. |
|
Flow<T> |
remove(Predicate<? super T> predicate)
Removes values where the predicate returns true, returning a new Flow with just the remaining values. |
|
Flow<T> |
rest()
Returns a new Flow containing all but the first value in this Flow. |
|
Flow<T> |
reverse()
Returns a new flow with the same elements but in reverse order. |
|
Flow<T> |
sort()
Sorts this Flow, forming a new Flow. |
|
Flow<T> |
sort(java.util.Comparator<? super T> comparator)
Sorts this Flow using the comparator, forming a new Flow. |
|
Flow<T> |
take(int length)
Returns a new Flow containing just the first values from this Flow. |
|
T[] |
toArray(java.lang.Class<T> type)
Converts the Flow into an array of values (due to type erasure, you have to remind the Flow about the type). |
|
java.util.List<T> |
toList()
Converts the Flow into an unmodifiable list of values. |
|
java.util.Set<T> |
toSet()
Converts the Flow into an unmodifiable set of values. |
|
| Methods inherited from interface java.lang.Iterable |
|---|
iterator |
| Method Detail |
|---|
<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
Flow<T> filter(Predicate<? super T> predicate)
Flow<T> remove(Predicate<? super T> predicate)
<A> A reduce(Reducer<A,T> reducer,
A initial)
Reducing is a non-lazy operation; it will fully realize the values of the Flow.
Flow<T> each(Worker<? super T> worker)
Each is a non-lazy operation; it will fully realize the values of the Flow.
java.util.List<T> toList()
java.util.Set<T> toSet()
T[] toArray(java.lang.Class<T> type)
Flow<T> reverse()
boolean isEmpty()
Flow<T> concat(Flow<? extends T> other)
Flow<T> concat(java.util.List<? extends T> list)
<V extends T> Flow<T> append(V... values)
Flow<T> sort()
java.lang.ClassCastException - if type ComparableFlow<T> sort(java.util.Comparator<? super T> comparator)
T first()
Flow<T> rest()
int count()
Predicates).
Flow<T> take(int length)
length - maximum number of values in the FlowFlow<T> drop(int length)
length - number of values to drop
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||