T - the element typepublic static interface C.ReversibleSequence<T> extends C.Sequence<T>
A bidirectional sequence which can be iterated from tail to head
C.Featured.Factory| Modifier and Type | Method and Description |
|---|---|
C.ReversibleSequence<T> |
accept(Lang.Visitor<? super T> visitor)
Iterate this
Traversable with a visitor function. |
C.ReversibleSequence<T> |
acceptLeft(Lang.Visitor<? super T> visitor)
Iterate through this sequence from head to tail with the visitor function specified
|
C.ReversibleSequence<T> |
acceptRight(Lang.Visitor<? 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(Lang.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(Lang.Visitor<? super T> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
C.ReversibleSequence<T> |
eager()
Returns this traversable and make sure
C.Feature.LAZY is unset |
C.ReversibleSequence<T> |
filter(Lang.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.
|
Lang.Option<T> |
findLast(Lang.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence from tail to head.
|
<R> C.ReversibleSequence<R> |
flatMap(Lang.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(Lang.Visitor<? super T> visitor)
Alias of
C.Traversable.accept(Lang.Visitor) |
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(Lang.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.
|
Lang.Option<T> |
reduceRight(Lang.Func2<T,T,T> accumulator)
Run reduction from tail to head.
|
<R> R |
reduceRight(R identity,
Lang.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(Lang.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<Lang.Binary<T,T2>> |
zip(C.ReversibleSequence<T2> rseq) |
<T2> C.ReversibleSequence<Lang.Binary<T,T2>> |
zipAll(C.ReversibleSequence<T2> rseq,
T def1,
T2 def2) |
append, append, append, append, asList, collect, 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()
Returns this traversable and make sure C.Feature.PARALLEL is set
parallel in interface C.Sequence<T>parallel in interface C.Traversable<T>C.ReversibleSequence<T> sequential()
Returns this traversable and make sure C.Feature.PARALLEL is unset
sequential in interface C.Sequence<T>sequential in interface C.Traversable<T>C.ReversibleSequence<T> lazy()
Returns this traversable and make sure C.Feature.LAZY is set
lazy in interface C.Sequence<T>lazy in interface C.Traversable<T>C.ReversibleSequence<T> eager()
Returns this traversable and make sure C.Feature.LAZY is unset
eager in interface C.Sequence<T>eager in interface C.Traversable<T>C.ReversibleSequence<T> head(int n)
Alias of 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()
Returns the rest part of the Sequence except the first element
tail in interface C.Sequence<T>C.Sequence.head(),
tail(int)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
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(Lang.Function<? super T,Boolean> predicate)
Returns an new 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)
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
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(Lang.Function<? super T,Boolean> predicate)
C.SequenceReturns a 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
dropWhile in interface C.Sequence<T>predicate - the function that check if drop operation should stopC.ReversibleSequence<T> filter(Lang.Function<? super T,Boolean> predicate)
C.SequenceReturns an new traversable that contains all elements in the current traversable except that does not pass the test of the filter function specified.
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)
Returns a sequence consists of all elements of this sequence followed by the element specified.
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)
Returns an new reversible sequence contains all elements in this sequence followed by all elements in the specified reverse sequence
seq - another reversible sequenceC.ReversibleSequence<T> prepend(T t)
Returns a sequence consists of the element specified followed by all elements of this sequence.
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)
Returns an new reversible sequence contains all elements in specified reversible sequence followed by all elements in this sequence
seq - another reversible sequenceT last() throws UnsupportedOperationException, NoSuchElementException
Returns the last element from this Sequence
UnsupportedOperationException - 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
Returns a 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
Returns an new Sequence that reverse this Sequence.
SequenceUnsupportedOperationException - if this Sequence is unlimitedC.Feature.LIMITED,
C.Featured.is(org.osgl.util.C.Feature)Iterator<T> reverseIterator()
Returns an Iterator iterate the sequence from tail to head
<R> R reduceRight(R identity,
Lang.Func2<R,T,R> accumulator)
Run reduction from tail side. This is equivalent to:
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 R#reduce(Object, Func2)Lang.Option<T> reduceRight(Lang.Func2<T,T,T> accumulator)
Run reduction from tail to head. This is equivalent to
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 resultLang.Option describing the accumulating resultLang.Option<T> findLast(Lang.Function<? super T,Boolean> predicate)
Apply the predicate specified to the element of this sequence from tail to head. Stop at the element that returns true, and returns an Lang.Option describing the element. If none of the element applications in the sequence returns true then Lang.none() is returned
predicate - the function map the element to BooleanLang.none()<R> C.ReversibleSequence<R> map(Lang.Function<? super T,? extends R> mapper)
C.SequenceReturns an new traversable with a mapper function specified. The element in the new traversal is the result of the mapper function applied to this traversal element.
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(Lang.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. If the result of the mapping function is 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(Lang.Visitor<? super T> visitor)
C.TraversableIterate this 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 parallel
accept 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(Lang.Visitor<? super T> visitor)
C.TraversableAlias of C.Traversable.accept(Lang.Visitor)
each in interface C.Sequence<T>each in interface C.Traversable<T>visitor - the visitor to tranverse the elementsTraversable instanceC.ReversibleSequence<T> forEach(Lang.Visitor<? super T> visitor)
C.TraversableAlias of C.Traversable.accept(Lang.Visitor)
forEach in interface C.Sequence<T>forEach in interface C.Traversable<T>visitor - the visitor functionTraversable instanceC.ReversibleSequence<T> acceptLeft(Lang.Visitor<? super T> visitor)
C.SequenceIterate through this sequence from head to tail with the visitor function specified
acceptLeft in interface C.Sequence<T>visitor - the function to visit elements in this sequenceC.Traversable.accept(Lang.Visitor),
acceptRight(Lang.Visitor)C.ReversibleSequence<T> acceptRight(Lang.Visitor<? super T> visitor)
Iterate through this sequence from tail to head with the visitor function specified
visitor - the function to visit elements in this sequenceC.Traversable.accept(Lang.Visitor),
C.Sequence.acceptLeft(Lang.Visitor)<T2> C.ReversibleSequence<Lang.Binary<T,T2>> zip(C.ReversibleSequence<T2> rseq)
<T2> C.ReversibleSequence<Lang.Binary<T,T2>> zipAll(C.ReversibleSequence<T2> rseq, T def1, T2 def2)
Copyright © 2014–2019 OSGL (Open Source General Library). All rights reserved.