T - the element typepublic static interface C.ReversibleSequence<T> extends C.Sequence<T>
C.Featured.Factory| Modifier and Type | Method and Description |
|---|---|
C.ReversibleSequence<T> |
accept(Osgl.Function<? super T,?> visitor)
Iterate this
Traversable with a visitor function. |
C.ReversibleSequence<T> |
acceptLeft(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from head to tail with
the visitor function specified
|
C.ReversibleSequence<T> |
acceptRight(Osgl.Function<? super T,?> visitor)
Iterate through this sequence from tail to head with the visitor function
specified
|
C.ReversibleSequence<T> |
append(C.ReversibleSequence<T> seq)
Returns an new reversible sequence contains all elements
in this sequence followed by all elements in the specified
reverse sequence
|
C.ReversibleSequence<T> |
append(T t)
Returns a sequence consists of all elements of this sequence
followed by the element specified.
|
C.ReversibleSequence<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.ReversibleSequence<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.ReversibleSequence<T> |
each(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.ReversibleSequence<T> |
eager()
Returns this traversable and make sure
C.Feature.LAZY is unset |
C.ReversibleSequence<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> |
findLast(Osgl.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence
from tail to head.
|
<R> C.ReversibleSequence<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.ReversibleSequence<T> |
forEach(Osgl.Function<? super T,?> visitor)
Alias of
C.Traversable.accept(Osgl.Function) |
C.ReversibleSequence<T> |
head(int n)
Alias of
C.Sequence.take(int) |
T |
last()
Returns the last element from this
Sequence |
C.ReversibleSequence<T> |
lazy()
Returns this traversable and make sure
C.Feature.LAZY is set |
<R> C.ReversibleSequence<R> |
map(Osgl.Function<? super T,? extends R> mapper)
Returns an new traversable with a mapper function specified.
|
C.ReversibleSequence<T> |
parallel()
Returns this traversable and make sure
C.Feature.PARALLEL is set |
C.ReversibleSequence<T> |
prepend(C.ReversibleSequence<T> seq)
Returns an new reversible sequence contains all elements
in specified reversible sequence followed by all elements
in this sequence
|
C.ReversibleSequence<T> |
prepend(T t)
Returns a sequence consists of the element specified followed by
all elements of this sequence.
|
Osgl.Option<T> |
reduceRight(Osgl.Func2<T,T,T> accumulator)
Run reduction from tail to head.
|
<R> R |
reduceRight(R identity,
Osgl.Func2<R,T,R> accumulator)
Run reduction from tail side.
|
C.ReversibleSequence<T> |
reverse()
Returns an new
Sequence that reverse this Sequence. |
Iterator<T> |
reverseIterator()
Returns an
Iterator iterate the sequence from tail to head |
C.ReversibleSequence<T> |
sequential()
Returns this traversable and make sure
C.Feature.PARALLEL is unset |
C.ReversibleSequence<T> |
tail()
Returns the rest part of the
Sequence except the first element |
C.ReversibleSequence<T> |
tail(int n)
Returns a
Sequence consisting the last n elements from this Sequence
if number n is positive and the Sequence contains more than n elements |
C.ReversibleSequence<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.ReversibleSequence<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.ReversibleSequence<Osgl.T2<T,T2>> |
zip(C.ReversibleSequence<T2> rseq) |
<T2> C.ReversibleSequence<Osgl.T2<T,T2>> |
zipAll(C.ReversibleSequence<T2> rseq,
T def1,
T2 def2) |
append, append, append, append, count, findFirst, first, head, prepend, prepend, prepend, prepend, reduce, reduce, reduceLeft, reduceLeft, zip, zipAll, zipWithIndexallMatch, anyMatch, findOne, isEmpty, noneMatch, sizeforEach, iterator, spliteratorfeatures, isC.ReversibleSequence<T> parallel()
C.Feature.PARALLEL is setparallel in interface C.Sequence<T>parallel in interface C.Traversable<T>C.ReversibleSequence<T> sequential()
C.Feature.PARALLEL is unsetsequential in interface C.Sequence<T>sequential in interface C.Traversable<T>C.ReversibleSequence<T> lazy()
C.Feature.LAZY is setlazy in interface C.Sequence<T>lazy in interface C.Traversable<T>C.ReversibleSequence<T> eager()
C.Feature.LAZY is unseteager in interface C.Sequence<T>eager in interface C.Traversable<T>C.ReversibleSequence<T> head(int n)
C.Sequence.take(int)head in interface C.Sequence<T>n - the number of elements to be taken into the return sequencen elements in this sequenceC.ReversibleSequence<T> tail()
Sequence except the first elementtail in interface C.Sequence<T>C.Sequence.head(),
tail(int)C.ReversibleSequence<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));
take in interface C.Sequence<T>n - specify the number of elements to be taken from the head of this Sequencen elements in this sequenceC.Sequence.head(int)C.ReversibleSequence<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)));
takeWhile in interface C.Sequence<T>predicate - specify which the elements in this Sequence will put into the new
SequenceC.ReversibleSequence<T> drop(int n)
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
drop in interface C.Sequence<T>n - specify the number of elements to be taken from the head of this Sequence or
the -n number of elements to be taken from the tail of this sequence if n is
an negative numbern number of elementsC.ReversibleSequence<T> dropWhile(Osgl.Function<? super T,Boolean> predicate)
C.SequenceSequence 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
dropWhile in interface C.Sequence<T>predicate - the function that check if drop operation should stopC.ReversibleSequence<T> filter(Osgl.Function<? super T,Boolean> predicate)
C.Sequence
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.Sequence<T>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 predicateC.ReversibleSequence<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
append in interface C.Sequence<T>t - the element to be appended to this sequencetC.ReversibleSequence<T> append(C.ReversibleSequence<T> seq)
seq - another reversible sequenceC.ReversibleSequence<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
prepend in interface C.Sequence<T>t - the element to be appended to this sequencet
followed this seq's elementC.ReversibleSequence<T> prepend(C.ReversibleSequence<T> seq)
seq - another reversible sequenceT last() throws UnsupportedOperationException, NoSuchElementException
SequenceUnsupportedOperationException - if this Sequence is not limitedNoSuchElementException - if the Sequence is emptyC.Traversable.isEmpty(),
C.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)C.ReversibleSequence<T> tail(int n) throws UnsupportedOperationException, IndexOutOfBoundsException
Sequence consisting the last 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 first -n elements from this
Sequence is returned in an new Sequence
Sequence seq = C1.list(1, 2, 3, 4);
assertEquals(C1.list(3, 4), seq.tail(2));
assertEquals(C1.list(1, 2, 3, 4), seq.tail(100));
assertEquals(C1.list(), seq.tail(0));
assertEquals(C1.list(1, 2, 3), seq.tail(-3));
assertEquals(C1.list(1, 2, 3, 4), seq.tail(-200));
This method does not mutate the underline container
n - specify the number of elements to be taken from the tail of this SequenceSequence consisting of the last n elements from this SequenceUnsupportedOperationException - if the traversal is unlimited or emptyIndexOutOfBoundsException - if n is greater than the size of this SequenceC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)C.ReversibleSequence<T> reverse() throws UnsupportedOperationException
Sequence that reverse this Sequence.SequenceUnsupportedOperationException - if this Sequence is unlimitedC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)Iterator<T> reverseIterator()
Iterator iterate the sequence from tail to head<R> R reduceRight(R identity,
Osgl.Func2<R,T,R> accumulator)
R result = identity;
for (T element: this sequence.reverse()) {
result = accumulator.apply(result, element);
}
return result;
R - the accumulation resultidentity - the initial valueaccumulator - the function performs accumulation from T an R to anthoer RC.Sequence.reduce(Object, Osgl.Func2)Osgl.Option<T> reduceRight(Osgl.Func2<T,T,T> accumulator)
if (isEmpty()) {
return _.none();
}
T result = last();
for (T element: this sequence.reverse.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> findLast(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()<R> C.ReversibleSequence<R> map(Osgl.Function<? super T,? extends R> mapper)
C.Sequence
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.Sequence<T>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.ReversibleSequence<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.Sequence<T>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.ReversibleSequence<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.Sequence<T>accept 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.ReversibleSequence<T> each(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)each in interface C.Sequence<T>each in interface C.Traversable<T>visitor - the visitor to tranverse the elementsTraversable instanceC.ReversibleSequence<T> forEach(Osgl.Function<? super T,?> visitor)
C.TraversableC.Traversable.accept(Osgl.Function)forEach in interface C.Sequence<T>forEach in interface C.Traversable<T>visitor - the visitor functionTraversable instanceC.ReversibleSequence<T> acceptLeft(Osgl.Function<? super T,?> visitor)
C.SequenceacceptLeft in interface C.Sequence<T>visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
acceptRight(Osgl.Function)C.ReversibleSequence<T> acceptRight(Osgl.Function<? super T,?> visitor)
visitor - the function to visit elements in this sequenceC.Traversable.accept(Osgl.Function),
C.Sequence.acceptLeft(Osgl.Function)<T2> C.ReversibleSequence<Osgl.T2<T,T2>> zip(C.ReversibleSequence<T2> rseq)
<T2> C.ReversibleSequence<Osgl.T2<T,T2>> zipAll(C.ReversibleSequence<T2> rseq, T def1, T2 def2)
Copyright © 2017. All Rights Reserved.