T - The element typepublic static interface C.Traversable<T> extends Iterable<T>, C.Featured
C.Featured.Factory| Modifier and Type | Method and Description |
|---|---|
C.Traversable<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
boolean |
allMatch(Osgl.Function<? super T,Boolean> predicate)
Check if all elements match the predicate specified
|
boolean |
anyMatch(Osgl.Function<? super T,Boolean> predicate)
Check if any elements matches the predicate specified
|
C.Traversable<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
accept(Osgl.Function) |
C.Traversable<T> |
eager()
Returns this traversable and turn off
C.Feature.LAZY |
C.Traversable<T> |
filter(Osgl.Function<? super T,Boolean> predicate)
Returns an new traversable that contains all elements in the current traversable
except that does not pass the test of the filter function specified.
|
Osgl.Option<T> |
findOne(Osgl.Function<? super T,Boolean> predicate)
Returns an element that matches the predicate specified.
|
<R> C.Traversable<R> |
flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
Returns a traversable consisting of the results of replacing each element of this
stream with the contents of the iterable produced by applying the provided mapping
function to each element.
|
C.Traversable<T> |
forEach(Osgl.Function<? super T,?> visitor)
Alias of
accept(Osgl.Function) |
boolean |
isEmpty()
Is this traversal empty?
|
C.Traversable<T> |
lazy()
Returns this traversable and try to turn on
C.Feature.LAZY. |
<R> C.Traversable<R> |
map(Osgl.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
boolean |
noneMatch(Osgl.Function<? super T,Boolean> predicate)
Check if no elements matches the predicate specified.
|
C.Traversable<T> |
parallel()
Returns this traversable and try to turn on
C.Feature.PARALLEL. |
Osgl.Option<T> |
reduce(Osgl.Func2<T,T,T> accumulator)
Performs a reduction on the elements in this traversable, using provided accumulating
function.
|
<R> R |
reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
Performs a reduction on the elements in this traversable, using the provided
identity and accumulating function.
|
C.Traversable<T> |
sequential()
Returns this traversable and turn off
C.Feature.PARALLEL |
int |
size()
Return the size of this traversal
|
forEach, iterator, spliteratorfeatures, isC.Traversable<T> parallel()
C.Feature.PARALLEL. If this traversable does not
support C.Feature.PARALLEL then
return this traversable directly without any state changeC.Traversable<T> sequential()
C.Feature.PARALLELC.Traversable<T> lazy()
C.Feature.LAZY.
If lazy is not supported then return this traversable directly without
any state changeC.Traversable<T> eager()
C.Feature.LAZYboolean isEmpty()
true if the traversal is empty or false otherwiseint size() throws UnsupportedOperationException
UnsupportedOperationException - if this structure does not support this method<R> C.Traversable<R> map(Osgl.Function<? super T,? extends R> mapper)
Traversable traversable = C.list(23, _.NONE, null);
assertEquals(C.list(true, false, false), traversal.map(_.F.NOT_NULL));
assertEquals(C.list("23", "", ""), traversal.map(_.F.AS_STRING));
For Lazy Traversable, it must use lazy evaluation for this method. Otherwise it is up to implementation to decide whether use lazy evaluation or not
R - the element type of the new traversalmapper - the function that applied to element in this traversal and returns element in the result traversal<R> C.Traversable<R> flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
null,
this is treated as if the result is an empty traversable.R - the element type of the the new traversablemapper - the function produce an iterable when applied to an elementC.Traversable<T> filter(Osgl.Function<? super T,Boolean> predicate)
Traversable traversable = C.list(-1, 0, 1, -3, 7);
Traversable filtered = traversable.filter(_.F.gt(0));
assertTrue(filtered.contains(1));
assertFalse(filtered.contains(-3));
predicate - the function that test if the element in the traversable should be
kept in the resulting traversable. When applying the filter function
to the element, if the result is true then the element will
be kept in the resulting traversable.<R> R reduce(R identity,
Osgl.Func2<R,T,R> accumulator)
R result = identity;
for (T element: this traversable) {
result = accumulator.apply(result, element);
}
return result;
The above shows a typical left side reduce. However depending on the implementation, it might choose another way to do the reduction, including reduction in a parallel way
R - the type of identity and the return valueidentity - the identity value for the accumulating functionaccumulator - the function the combine two valuesOsgl.Option<T> reduce(Osgl.Func2<T,T,T> accumulator)
boolean found = false;
T result = null;
for (T element: this traversable) {
if (found) {
result = accumulator.apply(result, element);
} else {
found = true;
result = element;
}
}
return found ? _.some(result) : _.none();
The above shows a typical left side reduction. However depending on the implementation, it might choose another way to do the reduction, including reduction in a parallel way
accumulator - the function takes previous accumulating
result and the current element being
iteratedOsgl.none() if
the structure is emptyboolean allMatch(Osgl.Function<? super T,Boolean> predicate)
predicate - the function to test the elementtrue if all elements match the predicateboolean anyMatch(Osgl.Function<? super T,Boolean> predicate)
predicate - the function to test the elementtrue if any element matches the predicateboolean noneMatch(Osgl.Function<? super T,Boolean> predicate)
this.allMatch(_.F.negate(predicate));
predicate - the function to test the elementtrue if none element matches the predicateOsgl.Option<T> findOne(Osgl.Function<? super T,Boolean> predicate)
predicate - the function map element to BooleanOsgl.NONE if no element matchesC.Traversable<T> accept(Osgl.Function<? super T,?> visitor)
Traversable with a visitor function. This method
does not specify the approach to iterate through this structure. The
implementation might choose iterate from left to right, or vice versa.
It might even choose to split the structure into multiple parts, and
iterate through them in parallelvisitor - a function that apply to element in this
Traversable. The return value
of the function is ignoredTraversable instance for chained callC.Traversable<T> each(Osgl.Function<? super T,?> visitor)
accept(Osgl.Function)visitor - the visitor to tranverse the elementsTraversable instanceC.Traversable<T> forEach(Osgl.Function<? super T,?> visitor)
accept(Osgl.Function)visitor - the visitor functionTraversable instanceCopyright © 2017. All Rights Reserved.