public static interface C.Sequence<T> extends C.Traversable<T>
C.Featured.Factory| Modifier and Type | Method and Description |
|---|---|
C.Sequence<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
C.Sequence<T> |
acceptLeft(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from head to tail with
the visitor function specified
|
C.Sequence<T> |
append(C.Sequence<? extends T> seq)
Returns a sequence consists of all elements of this sequence
followed by all elements of the specified sequence.
|
C.Sequence<T> |
append(Enumeration<? extends T> enumeration)
Returns a sequence consists of all elements of this sequence
followed by all elements of the specified enumeration.
|
C.Sequence<T> |
append(Iterable<? extends T> iterable)
Returns a sequence consists of all elements of this sequence
followed by all elements of the specified iterable.
|
C.Sequence<T> |
append(Iterator<? extends T> iterator)
Returns a sequence consists of all elements of this sequence
followed by all elements of the specified iterator.
|
C.Sequence<T> |
append(T t)
Returns a sequence consists of all elements of this sequence
followed by the element specified.
|
int |
count(T t)
Count the element occurence in this sequence
|
C.Sequence<T> |
drop(int n)
Returns a
Sequence consisting of the elements from this Sequence except the first n
if number n is positive and the Sequence contains more than n elements |
C.Sequence<T> |
dropWhile(Osgl.Function<? super T,Boolean> predicate)
Returns a
Sequence consisting of the elements from this sequence with leading elements
dropped until the predicate returns true |
C.Sequence<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.Sequence<T> |
eager()
Returns this traversable and make sure
C.Feature.LAZY is unset |
C.Sequence<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> |
findFirst(Osgl.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence
from head to tail.
|
T |
first()
Alias of
head() |
<R> C.Sequence<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.Sequence<T> |
forEach(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
T |
head()
|
C.Sequence<T> |
head(int n)
Alias of
take(int) |
C.Sequence<T> |
lazy()
Returns this traversable and make sure
C.Feature.LAZY is set |
<R> C.Sequence<R> |
map(Osgl.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
C.Sequence<T> |
parallel()
Returns this traversable and make sure
C.Feature.PARALLEL is set |
C.Sequence<T> |
prepend(C.Sequence<? extends T> seq)
Returns a sequence consists of all elements of the sequence specified
followed by all elements of this sequence
|
C.Sequence<T> |
prepend(Enumeration<? extends T> enumeration)
Returns a sequence consists of all elements of the enumeration specified
followed by all elements of this sequence
|
C.Sequence<T> |
prepend(Iterable<? extends T> iterable)
Returns a sequence consists of all elements of the iterable specified
followed by all elements of this sequence
|
C.Sequence<T> |
prepend(Iterator<? extends T> iterator)
Returns a sequence consists of all elements of the iterator specified
followed by all elements of this sequence
|
C.Sequence<T> |
prepend(T t)
Returns a sequence consists of the element specified followed by
all elements of this sequence.
|
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.
|
Osgl.Option<T> |
reduceLeft(Osgl.Func2<T,T,T> accumulator)
Run reduction from head to tail.
|
<R> R |
reduceLeft(R identity,
Osgl.Func2<R,T,R> accumulator)
Run reduction from header side.
|
C.Sequence<T> |
sequential()
Returns this traversable and make sure
C.Feature.PARALLEL is unset |
C.Sequence<T> |
tail()
Returns the rest part of the
Sequence except the first element |
C.Sequence<T> |
take(int n)
Returns a
Sequence consisting the first n elements from this Sequence if
number n is positive and the Sequence contains more than n elements |
C.Sequence<T> |
takeWhile(Osgl.Function<? super T,Boolean> predicate)
Returns an new
Sequence that takes the head of this Sequence until the predicate
evaluate to false: |
<T2> C.Sequence<Osgl.T2<T,T2>> |
zip(Iterable<T2> iterable)
Returns a sequence formed from this sequence and another iterable
collection by combining corresponding elements in pairs.
|
<T2> C.Sequence<Osgl.T2<T,T2>> |
zipAll(Iterable<T2> iterable,
T def1,
T2 def2)
Returns a sequence formed from this sequence and another iterable
collection by combining corresponding elements in pairs.
|
C.Sequence<Osgl.T2<T,Integer>> |
zipWithIndex()
Zip this sequence with its indices
|
allMatch, anyMatch, findOne, isEmpty, noneMatch, sizeforEach, iterator, spliteratorfeatures, isC.Sequence<T> parallel()
C.Feature.PARALLEL is setparallel in interface C.Traversable<T>C.Sequence<T> sequential()
C.Feature.PARALLEL is unsetsequential in interface C.Traversable<T>C.Sequence<T> lazy()
C.Feature.LAZY is setlazy in interface C.Traversable<T>C.Sequence<T> eager()
C.Feature.LAZY is unseteager in interface C.Traversable<T>T first() throws NoSuchElementException
head()NoSuchElementExceptionT head() throws NoSuchElementException
SequenceNoSuchElementException - if the Sequence is emptytail(),
first()C.Sequence<T> head(int n)
take(int)n - the number of elements to be taken into the return sequencen element in the sequenceC.Sequence<T> tail() throws UnsupportedOperationException
Sequence except the first elementSequence without the first elementUnsupportedOperationException - if the Sequence is emptyhead(),
C.ReversibleSequence.tail(int)C.Sequence<T> take(int n)
Sequence consisting the first n elements from this Sequence if
number n is positive and the Sequence contains more than n elements
If this Sequence contains less than n elements, then a Sequence consisting
the whole elements of this Sequence is returned. Note it might return this Sequence
itself if the Sequence is immutable.
If the number n is zero, then an empty Sequence is returned in reverse
order
If the number n is negative, then the last -n elements from this
Sequence is returned in an new Sequence, or throw UnsupportedOperationException
if this operation is not supported
Sequence seq = C.list(1, 2, 3, 4);
assertEquals(C.list(1, 2), seq.take(2));
assertEquals(C.list(1, 2, 3, 4), seq.take(100));
assertEquals(C.list(), seq.take(0));
assertEquals(C.list(3, 4), seq.take(-2));
assertEquals(C.list(1, 2, 3, 4), seq.take(-200));
n - specify the number of elements to be taken from the head of this SequenceSequence consisting of the first n elements of this Sequencehead(int)C.Sequence<T> takeWhile(Osgl.Function<? super T,Boolean> predicate)
Sequence that takes the head of this Sequence until the predicate
evaluate to false:
C.Sequence seq = C.list(1, 2, 3, 4, 5, 4, 3, 2, 1);
assertEquals(C.list(C.list(1, 2, 3), seq.takeWhile(_.F.lt(4)));
assertEquals(C.list(C.list(1, 2, 3, 3, 2, 1), seq.filter(_.F.lt(4)));
predicate - specify which the elements in this Sequence will put into the new
SequenceSequenceC.Sequence<T> drop(int n) throws IllegalArgumentException
Sequence consisting of the elements from this Sequence except the first n
if number n is positive and the Sequence contains more than n elements
If this Sequence contains less than n elements, then an empty Sequence
is returned
If the number n is zero, then a copy of this Sequence or this Sequence
itself is returned depending on the implementation
If the number n is negative, then either IllegalArgumentException should
be thrown out if this sequence is not C.Feature.LIMITED or it drop
-n element starts from the tail side
C.Sequence seq = C.list(1, 2, 3, 4, 5);
assertEquals(C.list(3, 4, 5), seq.drop(2));
assertEquals(C.list(1, 2, 3, 4, 5), seq.drop(0));
assertEquals(C.list(), seq.drop(100));
Note this method does NOT modify the current sequence, instead it returns an new sequence structure containing the elements as required
n - specify the number of elements to be taken from the head of this Sequence
must not less than 0Sequence consisting of the elements of this Sequence except the first n onesIllegalArgumentExceptionC.Sequence<T> dropWhile(Osgl.Function<? super T,Boolean> predicate)
Sequence consisting of the elements from this sequence with leading elements
dropped until the predicate returns true
Sequence seq = C.list(1, 2, 3, 4, 3, 2, 1);
assertTrue(C.list(), seq.dropWhile(_.F.gt(100)));
assertTrue(C.list(4, 3, 2, 1), seq.dropWhile(_.F.lt(3)));
Note this method does NOT modify the current sequence, instead it returns an new sequence structure containing the elements as required
predicate - the function that check if drop operation should stopC.Sequence<T> append(Iterable<? extends T> iterable)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might append specified seq to this sequence instance
directly
iterable - the iterable in which elements will be append to this sequenceC.Sequence<T> append(C.Sequence<? extends T> seq)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might append specified seq to this sequence instance
directly
seq - the sequence to be appendedC.Sequence<T> append(Iterator<? extends T> iterator)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might append specified seq to this sequence instance
directly
iterator - the iterator in which elements will be append to the returned sequenceC.Sequence<T> append(Enumeration<? extends T> enumeration)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might append specified seq to this sequence instance
directly
enumeration - the enumeration in which elements will be append to the returned sequenceC.Sequence<T> append(T t)
an immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might append the element to this sequence instance
directly
t - the element to be appended to this sequencetC.Sequence<T> prepend(Iterable<? extends T> iterable)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might prepend specified seq to this sequence instance
directly
iterable - the iterable to be prependedC.Sequence<T> prepend(Iterator<? extends T> iterator)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might prepend specified seq to this sequence instance
directly
iterator - the iterator to be prependedC.Sequence<T> prepend(Enumeration<? extends T> enumeration)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might prepend specified seq to this sequence instance
directly
enumeration - the enumeration to be prependedC.Sequence<T> prepend(C.Sequence<? extends T> seq)
An immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might prepend specified seq to this sequence instance
directly
seq - the sequence to be prependedC.Sequence<T> prepend(T t)
an immutable Sequence must
return an new Sequence; while a mutable Sequence implementation
might append the element to this sequence instance
directly
t - the element to be appended to this sequencet followed
by all elements in this sequence<R> C.Sequence<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
map in interface C.Traversable<T>R - the element type of the new traversalmapper - the function that applied to element in this traversal and returns element in the result traversalR that are mapped from this sequence<R> C.Sequence<R> flatMap(Osgl.Function<? super T,? extends Iterable<? extends R>> mapper)
null,
this is treated as if the result is an empty traversable.flatMap in interface C.Traversable<T>R - the element type of the the new traversablemapper - the function produce an iterable when applied to an elementR type element that are mapped from this sequencesC.Sequence<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));
filter in interface C.Traversable<T>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.Sequence consists of elements that passed the predicate<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
This method does not specify how to run the accumulator. It might bereduceLeft(Object, Osgl.Func2) or
C.ReversibleSequence.reduceRight(Object, Osgl.Func2), or
even run reduction in parallel, it all depending on the implementation.
For a guaranteed reduce from left to right, use
reduceLeft(Object, Osgl.Func2) instead
reduce in interface C.Traversable<T>R - the type of identity and the return valueidentity - the identity value for the accumulating functionaccumulator - the function the combine two values<R> R reduceLeft(R identity,
Osgl.Func2<R,T,R> accumulator)
R result = identity;
for (T element: this sequence) {
result = accumulator.apply(result, element);
}
return result;
R - the aggregation result typeidentity - the identity value for the accumulating functionaccumulator - the function to accumulate 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
This method does not specify the approach to run reduction. For a guaranteed reduction from head to tail, usereduceLeft(Osgl.Func2) insteadreduce in interface C.Traversable<T>accumulator - the function takes previous accumulating
result and the current element being
iteratedOsgl.none() if
the structure is emptyOsgl.Option<T> reduceLeft(Osgl.Func2<T,T,T> accumulator)
if (isEmpty()) {
return _.none();
}
T result = head();
for (T element: this traversable.tail()) {
result = accumulator.apply(result, element);
}
return _.some(result);
accumulator - the function accumulate each element to the final result$.Option describing the accumulating resultOsgl.Option<T> findFirst(Osgl.Function<? super T,Boolean> predicate)
true,
and returns an $.Option describing the element. If none
of the element applications in the sequence returns true
then Osgl.none() is returnedpredicate - the function map the element to BooleanOsgl.none()C.Sequence<T> accept(Osgl.Function<? super T,?> visitor)
C.TraversableTraversable 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 parallelaccept in interface C.Traversable<T>visitor - a function that apply to element in this
Traversable. The return value
of the function is ignoredTraversable instance for chained callC.Sequence<T> each(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)each in interface C.Traversable<T>visitor - the visitor to tranverse the elementsTraversable instanceC.Sequence<T> forEach(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)forEach in interface C.Traversable<T>visitor - the visitor functionTraversable instanceC.Sequence<T> acceptLeft(Osgl.Function<? super T,?> visitor)
visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
C.ReversibleSequence.acceptRight(Osgl.Function)<T2> C.Sequence<Osgl.T2<T,T2>> zip(Iterable<T2> iterable)
T2 - the type of the iterableiterable - the part B to be zipped with this sequence<T2> C.Sequence<Osgl.T2<T,T2>> zipAll(Iterable<T2> iterable, T def1, T2 def2)
T2 - the type of the iterableiterable - the part B to be zipped with this sequencedef1 - the element to be used to fill up the result if
this sequence is shorter than that iterabledef2 - the element to be used to fill up the result if
the iterable is shorter than this sequenceC.Sequence<Osgl.T2<T,Integer>> zipWithIndex()
int count(T t)
t - the elementCopyright © 2017. All Rights Reserved.