T
- Component typepublic interface Seq<T> extends Traversable<T>, Function1<Integer,T>
Creation:
Filtering:remove(Object)
removeAll(Object)
removeAll(Iterable)
removeAt(int)
removeFirst(Predicate)
removeLast(Predicate)
append(Object)
appendAll(Iterable)
insert(int, Object)
insertAll(int, Iterable)
prepend(Object)
prependAll(Iterable)
update(int, Object)
get(int)
indexOf(Object)
indexOf(Object, int)
lastIndexOf(Object)
lastIndexOf(Object, int)
slice(long, long)
subSequence(int)
subSequence(int, int)
λ.Memoized
Modifier and Type | Field and Description |
---|---|
static long |
serialVersionUID |
Modifier and Type | Method and Description |
---|---|
Seq<T> |
append(T element)
Appends an element to this.
|
Seq<T> |
appendAll(Iterable<? extends T> elements)
Appends all given elements to this.
|
default T |
apply(Integer index)
A
Seq is a partial function which returns the element at the specified index by calling
get(int). |
Seq<? extends Seq<T>> |
combinations()
Returns the union of all combinations from k = 0 to length().
|
Seq<? extends Seq<T>> |
combinations(int k)
Returns the k-combination of this traversable, i.e.
|
default boolean |
containsSlice(Iterable<? extends T> that)
Tests whether this sequence contains a given sequence as a slice.
|
default Iterator<Tuple2<T,T>> |
crossProduct()
Calculates the cross product (, i.e.
|
Iterator<? extends Seq<T>> |
crossProduct(int power)
Calculates the n-ary cartesian power (or cross product or simply product) of this.
|
default <U> Iterator<Tuple2<T,U>> |
crossProduct(Iterable<? extends U> that)
Calculates the cross product
this x that . |
Seq<T> |
distinct()
Returns a new version of this which contains no duplicates.
|
Seq<T> |
distinctBy(Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
<U> Seq<T> |
distinctBy(Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
Seq<T> |
drop(long n)
Drops the first n elements of this or all elements, if this length < n.
|
Seq<T> |
dropRight(long n)
Drops the last n elements of this or all elements, if this length < n.
|
Seq<T> |
dropUntil(Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
Seq<T> |
dropWhile(Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.
|
default boolean |
endsWith(Seq<? extends T> that)
Tests whether this sequence ends with the given sequence.
|
Seq<T> |
filter(Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
<U> Seq<U> |
flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
default <U> U |
foldRight(U zero,
BiFunction<? super T,? super U,? extends U> f)
Accumulates the elements of this Traversable by successively calling the given function
f from the right,
starting with a value zero of type B. |
T |
get(int index)
Returns the element at the specified index.
|
<C> Map<C,? extends Seq<T>> |
groupBy(Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends Seq<T>> |
grouped(long size)
Groups this
Traversable into fixed size blocks. |
default int |
indexOf(T element)
Returns the index of the first occurrence of the given element or -1 if this does not contain the given element.
|
int |
indexOf(T element,
int from)
Returns the index of the first occurrence of the given element after or at some start index
or -1 if this does not contain the given element.
|
default int |
indexOfSlice(Iterable<? extends T> that)
Finds first index where this sequence contains a given sequence as a slice.
|
default int |
indexOfSlice(Iterable<? extends T> that,
int from)
Finds first index after or at a start index where this sequence contains a given sequence as a slice.
|
default int |
indexWhere(Predicate<? super T> p)
Finds index of first element satisfying some predicate.
|
int |
indexWhere(Predicate<? super T> predicate,
int from)
Finds index of the first element satisfying some predicate after or at
some start index.
|
Seq<T> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<? extends Seq<T>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option . |
Seq<T> |
insert(int index,
T element)
Inserts the given element at the specified index.
|
Seq<T> |
insertAll(int index,
Iterable<? extends T> elements)
Inserts the given elements at the specified index.
|
Seq<T> |
intersperse(T element)
Inserts an element between all elements of this Traversable.
|
default Iterator<T> |
iterator(int index)
Returns an iterator of this elements starting at the given index.
|
default int |
lastIndexOf(T element)
Returns the index of the last occurrence of the given element or -1 if this does not contain the given element.
|
int |
lastIndexOf(T element,
int end)
Returns the index of the last occurrence of the given element before or at a given end index
or -1 if this does not contain the given element.
|
default int |
lastIndexOfSlice(Iterable<? extends T> that)
Finds last index where this sequence contains a given sequence as a slice.
|
int |
lastIndexOfSlice(Iterable<? extends T> that,
int end)
Finds last index before or at a given end index where this sequence contains a given sequence as a slice.
|
default int |
lastIndexWhere(Predicate<? super T> predicate)
Finds index of last element satisfying some predicate.
|
int |
lastIndexWhere(Predicate<? super T> predicate,
int end)
Finds index of last element satisfying some predicate before or at given
end index.
|
<U> Seq<U> |
map(Function<? super T,? extends U> mapper)
Maps the elements of this
Traversable to elements of a new type preserving their order, if any. |
static <T> Seq<T> |
narrow(Seq<? extends T> seq)
Narrows a widened
Seq<? extends T> to Seq<T>
by performing a type safe-cast. |
Seq<T> |
padTo(int length,
T element)
A copy of this sequence with an element appended until a given target length is reached.
|
Tuple2<? extends Seq<T>,? extends Seq<T>> |
partition(Predicate<? super T> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct tarversables
according to a predicate. |
Seq<T> |
patch(int from,
Iterable<? extends T> that,
int replaced)
Produces a new list where a slice of elements in this list is replaced by another sequence.
|
Seq<T> |
peek(Consumer<? super T> action)
Performs the given
action on the first element if this is an eager implementation. |
Seq<? extends Seq<T>> |
permutations()
Computes all unique permutations.
|
default int |
prefixLength(Predicate<? super T> predicate)
Returns the length of the longest prefix whose elements all satisfy some predicate.
|
Seq<T> |
prepend(T element)
Prepends an element to this.
|
Seq<T> |
prependAll(Iterable<? extends T> elements)
Prepends all given elements to this.
|
Seq<T> |
remove(T element)
Removes the first occurrence of the given element.
|
Seq<T> |
removeAll(Iterable<? extends T> elements)
Removes all occurrences of the given elements.
|
Seq<T> |
removeAll(T element)
Removes all occurrences of the given element.
|
Seq<T> |
removeAt(int index)
Removes the element at the specified position in this sequence.
|
Seq<T> |
removeFirst(Predicate<T> predicate)
Removes the first occurrence that satisfy predicate
|
Seq<T> |
removeLast(Predicate<T> predicate)
Removes the last occurrence that satisfy predicate
|
Seq<T> |
replace(T currentElement,
T newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
Seq<T> |
replaceAll(T currentElement,
T newElement)
Replaces all occurrences of the given currentElement with newElement.
|
Seq<T> |
retainAll(Iterable<? extends T> elements)
Keeps all occurrences of the given elements from this.
|
Seq<T> |
reverse()
Reverses the order of elements.
|
Iterator<T> |
reverseIterator()
An iterator yielding elements in reversed order.
|
Seq<T> |
scan(T zero,
BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
<U> Seq<U> |
scanLeft(U zero,
BiFunction<? super U,? super T,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going left to right.
|
<U> Seq<U> |
scanRight(U zero,
BiFunction<? super T,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going right to left.
|
int |
search(T element)
Searches this sequence for a specific element.
|
int |
search(T element,
Comparator<? super T> comparator)
Searches this sequence for a specific element.
|
int |
segmentLength(Predicate<? super T> predicate,
int from)
Computes length of longest segment whose elements all satisfy some predicate.
|
Seq<T> |
slice(long beginIndex,
long endIndex)
Returns a Seq that is a slice of this.
|
Iterator<? extends Seq<T>> |
sliding(long size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(long, long) . |
Iterator<? extends Seq<T>> |
sliding(long size,
long step)
Slides a window of a specific
size and step size over this Traversable . |
<U> Seq<T> |
sortBy(Comparator<? super U> comparator,
Function<? super T,? extends U> mapper)
Sorts this elements by comparing the elements in a different domain, using the given
mapper . |
<U extends Comparable<? super U>> |
sortBy(Function<? super T,? extends U> mapper)
Sorts this elements by comparing the elements in a different domain, using the given
mapper . |
Seq<T> |
sorted()
Sorts this elements according to their natural order.
|
Seq<T> |
sorted(Comparator<? super T> comparator)
Sorts this elements according to the provided
Comparator . |
Tuple2<? extends Seq<T>,? extends Seq<T>> |
span(Predicate<? super T> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the given
predicate and the second element is the remainder. |
Tuple2<? extends Seq<T>,? extends Seq<T>> |
splitAt(long n)
Splits a Seq at the specified index.
|
Tuple2<? extends Seq<T>,? extends Seq<T>> |
splitAt(Predicate<? super T> predicate)
Splits a sequence at the first element which satisfies the
Predicate , e.g. |
Tuple2<? extends Seq<T>,? extends Seq<T>> |
splitAtInclusive(Predicate<? super T> predicate)
Splits a sequence at the first element which satisfies the
Predicate , e.g. |
default boolean |
startsWith(Iterable<? extends T> that)
Tests whether this list starts with the given sequence.
|
default boolean |
startsWith(Iterable<? extends T> that,
int offset)
Tests whether this list contains the given sequence at a given index.
|
Seq<T> |
subSequence(int beginIndex)
Returns a Seq that is a subsequence of this.
|
Seq<T> |
subSequence(int beginIndex,
int endIndex)
Returns a Seq that is a subsequence of this.
|
Seq<T> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<? extends Seq<T>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option . |
Seq<T> |
take(long n)
Takes the first n elements of this or all elements, if this length < n.
|
Seq<T> |
takeRight(long n)
Takes the last n elements of this or all elements, if this length < n.
|
Seq<T> |
takeUntil(Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
Seq<T> |
takeWhile(Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
<U> Seq<U> |
unit(Iterable<? extends U> iterable) |
<T1,T2> Tuple2<? extends Seq<T1>,? extends Seq<T2>> |
unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct
sets.
|
<T1,T2,T3> Tuple3<? extends Seq<T1>,? extends Seq<T2>,? extends Seq<T3>> |
unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct
sets.
|
Seq<T> |
update(int index,
T element)
Updates the given element at the specified index.
|
<U> Seq<Tuple2<T,U>> |
zip(Iterable<U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
<U> Seq<Tuple2<T,U>> |
zipAll(Iterable<U> that,
T thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
Seq<Tuple2<T,Long>> |
zipWithIndex()
Zips this traversable with its indices.
|
average, containsAll, count, existsUnique, find, findLast, foldLeft, get, hasDefiniteSize, hash, head, headOption, isEmpty, isSingleValued, isTraversableAgain, iterator, last, lastOption, length, max, maxBy, maxBy, min, minBy, minBy, mkString, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, size, sum
fold, reduce, reduceOption
contains, corresponds, eq, equals, exists, forAll, forEach, getOption, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, hashCode, narrow, out, out, stderr, stdout, stringPrefix, toArray, toCharSeq, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaOptional, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toList, toMap, toOption, toQueue, toRight, toRight, toSet, toStack, toStream, toString, toTree, toTry, toTry, toVector
spliterator
andThen, arity, compose, curried, identity, lift, memoized, of, reversed, tupled
isMemoized
static final long serialVersionUID
static <T> Seq<T> narrow(Seq<? extends T> seq)
Seq<? extends T>
to Seq<T>
by performing a type safe-cast. This is eligible because immutable/read-only
collections are covariant.T
- Component type of the Seq
.seq
- A Seq
.seq
instance as narrowed type Seq<T>
.default T apply(Integer index)
Seq
is a partial function which returns the element at the specified index by calling
get(int).Seq<T> append(T element)
element
- An elementSeq<T> appendAll(Iterable<? extends T> elements)
elements
- An Iterable of elementsNullPointerException
- if elements
is nullSeq<? extends Seq<T>> combinations()
Examples:
[].combinations() = [[]]
[1,2,3].combinations() = [
[], // k = 0
[1], [2], [3], // k = 1
[1,2], [1,3], [2,3], // k = 2
[1,2,3] // k = 3
]
Seq<? extends Seq<T>> combinations(int k)
k
- Size of subsetsdefault boolean containsSlice(Iterable<? extends T> that)
Note: may not terminate for infinite-sized collections.
that
- the sequence to testNullPointerException
- if that
is null.default Iterator<Tuple2<T,T>> crossProduct()
this x this
.
Example:
// = List of Tuples (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)
List.of(1, 2, 3).crossProduct();
this
Iterator<? extends Seq<T>> crossProduct(int power)
Example:
// = ((A,A), (A,B), (A,C), ..., (B,A), (B,B), ..., (Z,Y), (Z,Z))
CharSeq.rangeClosed('A', 'Z').crossProduct(2);
power
- the number of cartesian multiplicationsdefault <U> Iterator<Tuple2<T,U>> crossProduct(Iterable<? extends U> that)
this x that
.
Example:
// = List of Tuples (1, 'a'), (1, 'b'), (2, 'a'), (2, 'b'), (3, 'a'), (3, 'b')
List.of(1, 2, 3).crossProduct(List.of('a', 'b');
U
- Component typethat
- Another iterablethis x that
NullPointerException
- if that is nulldefault boolean endsWith(Seq<? extends T> that)
Note: If the both the receiver object this and the argument that are infinite sequences this method may not terminate.
that
- the sequence to testT get(int index)
index
- an indexIndexOutOfBoundsException
- if this is empty, index < 0 or index >= length()default int indexOf(T element)
element
- an elementint indexOf(T element, int from)
element
- an elementfrom
- start indexdefault int indexOfSlice(Iterable<? extends T> that)
Note: may not terminate for infinite-sized collections.
that
- the sequence to testNullPointerException
- if that
is null.default int indexOfSlice(Iterable<? extends T> that, int from)
Note: may not terminate for infinite-sized collections.
that
- the sequence to testfrom
- the start indexNullPointerException
- if that
is null.default int indexWhere(Predicate<? super T> p)
p
- the predicate used to test elements.predicate
, or -1
, if none exists.int indexWhere(Predicate<? super T> predicate, int from)
predicate
- the predicate used to test elements.from
- the start index>= from
of the first element of this Seq that
satisfies the given predicate
, or -1
, if none exists.Seq<T> insert(int index, T element)
index
- an indexelement
- an elementIndexOutOfBoundsException
- if this is empty, index < 0 or index >= length()Seq<T> insertAll(int index, Iterable<? extends T> elements)
index
- an indexelements
- An Iterable of elementsIndexOutOfBoundsException
- if this is empty, index < 0 or index >= length()Seq<T> intersperse(T element)
element
- An element.default Iterator<T> iterator(int index)
this.subSequence(index).iterator()
.index
- an indexIndexOutOfBoundsException
- if index < 0 or index > length()default int lastIndexOf(T element)
element
- an elementdefault int lastIndexWhere(Predicate<? super T> predicate)
predicate
- the predicate used to test elements.predicate
, or -1
,
if none exists.int lastIndexWhere(Predicate<? super T> predicate, int end)
predicate
- the predicate used to test elements.end
- the maximum index of the search<= end
of the last element of this Seq that
satisfies the given predicate
, or -1
, if none exists.int lastIndexOf(T element, int end)
element
- an elementend
- the end indexdefault int lastIndexOfSlice(Iterable<? extends T> that)
Note: will not terminate for infinite-sized collections.
that
- the sequence to testNullPointerException
- if that
is null.int lastIndexOfSlice(Iterable<? extends T> that, int end)
that
- the sequence to testend
- the end indexNullPointerException
- if that
is null.Seq<T> padTo(int length, T element)
length
- the target lengthelement
- the padding elementelement
so that the resulting sequence has a length of at least length
.Seq<T> patch(int from, Iterable<? extends T> that, int replaced)
from
- the index of the first replaced elementthat
- sequence for replacementreplaced
- the number of elements to drop in the original listSeq<? extends Seq<T>> permutations()
Example:
[].permutations() = []
[1,2,3].permutations() = [
[1,2,3],
[1,3,2],
[2,1,3],
[2,3,1],
[3,1,2],
[3,2,1]
]
default int prefixLength(Predicate<? super T> predicate)
predicate
- the predicate used to test elements.Seq<T> prepend(T element)
element
- An elementSeq<T> prependAll(Iterable<? extends T> elements)
elements
- An Iterable of elementsSeq<T> remove(T element)
element
- An element to be removed from this Seq.Seq<T> removeAll(T element)
element
- An element to be removed from this Seq.Seq<T> removeAll(Iterable<? extends T> elements)
elements
- Elements to be removed from this Seq.NullPointerException
- if elements
is nullSeq<T> removeAt(int index)
index
- position of element to removeIndexOutOfBoundsException
- if this is empty, index < 0 or index >= length()Seq<T> removeFirst(Predicate<T> predicate)
predicate
- an predicateSeq<T> removeLast(Predicate<T> predicate)
predicate
- an predicateIterator<T> reverseIterator()
Note: xs.reverseIterator()
is the same as xs.reverse().iterator()
but might
be more efficient.
int segmentLength(Predicate<? super T> predicate, int from)
predicate
- the predicate used to test elements.from
- the index where the search starts.Seq<T> slice(long beginIndex, long endIndex)
beginIndex
and extends to the element at index endIndex - 1
.
Examples:
List.of(1, 2, 3, 4).slice(1, 3); // = (2, 3)
List.of(1, 2, 3, 4).slice(0, 4); // = (1, 2, 3, 4)
List.of(1, 2, 3, 4).slice(2, 2); // = ()
List.of(1, 2).slice(1, 0); // = ()
List.of(1, 2).slice(-10, 10); // = (1, 2)
See also subSequence(int, int)
which throws in some cases instead of returning a sequence.beginIndex
- the beginning index, inclusiveendIndex
- the end index, exclusiveSeq<T> sorted()
Comparable
, a java.lang.ClassCastException
may be thrown.ClassCastException
- if this elements are not Comparable
Seq<T> sorted(Comparator<? super T> comparator)
Comparator
. If this elements are not
Comparable
, a java.lang.ClassCastException
may be thrown.comparator
- A comparator<U extends Comparable<? super U>> Seq<T> sortBy(Function<? super T,? extends U> mapper)
mapper
.U
- The domain where elements are comparedmapper
- A mapper<U> Seq<T> sortBy(Comparator<? super U> comparator, Function<? super T,? extends U> mapper)
mapper
.U
- The domain where elements are comparedcomparator
- A comparatormapper
- A mapperTuple2<? extends Seq<T>,? extends Seq<T>> splitAt(long n)
splitAt(n)
is equivalent to
Tuple.of(take(n), drop(n))
.n
- An index.Tuple2<? extends Seq<T>,? extends Seq<T>> splitAt(Predicate<? super T> predicate)
Predicate
, e.g. Tuple(init, element+tail).predicate
- An predicateTuple
containing divided sequencesTuple2<? extends Seq<T>,? extends Seq<T>> splitAtInclusive(Predicate<? super T> predicate)
Predicate
, e.g. Tuple(init+element, tail).predicate
- An predicateTuple
containing divided sequencesdefault boolean startsWith(Iterable<? extends T> that)
that
- the sequence to testdefault boolean startsWith(Iterable<? extends T> that, int offset)
Note: If the both the receiver object this and the argument that are infinite sequences this method may not terminate.
that
- the sequence to testoffset
- the index where the sequence is searched.Seq<T> subSequence(int beginIndex)
beginIndex
and extends to the end of this Seq.
Examples:
List.of(1, 2).subSequence(0); // = (1, 2)
List.of(1, 2).subSequence(1); // = (2)
List.of(1, 2).subSequence(2); // = ()
List.of(1, 2).subSequence(10); // throws IndexOutOfBoundsException
List.of(1, 2).subSequence(-10); // throws IndexOutOfBoundsException
See also drop(long)
which is similar but does not throw.beginIndex
- the beginning index, inclusiveIndexOutOfBoundsException
- if beginIndex
is negative or larger than the length of this
String
object.Seq<T> subSequence(int beginIndex, int endIndex)
beginIndex
and extends to the element at index endIndex - 1
.
Examples:
List.of(1, 2, 3, 4).subSequence(1, 3); // = (2, 3)
List.of(1, 2, 3, 4).subSequence(0, 4); // = (1, 2, 3, 4)
List.of(1, 2, 3, 4).subSequence(2, 2); // = ()
List.of(1, 2).subSequence(1, 0); // throws IndexOutOfBoundsException
List.of(1, 2).subSequence(-10, 1); // throws IndexOutOfBoundsException
List.of(1, 2).subSequence(0, 10); // throws IndexOutOfBoundsException
See also slice(long, long)
which returns an empty sequence instead of throwing.beginIndex
- the beginning index, inclusiveendIndex
- the end index, exclusiveIndexOutOfBoundsException
- if beginIndex
or endIndex
is negative,
if endIndex
is greater than length()
,
or if beginIndex
is greater than endIndex
Seq<T> update(int index, T element)
index
- an indexelement
- an elementIndexOutOfBoundsException
- if this is empty, index < 0 or index >= length()int search(T element)
If this sequence is an `IndexedSeq`, a binary search is used. Otherwise, a linear search is used.
element
- the element to findClassCastException
- if T cannot be cast to Comparable<? super T>
int search(T element, Comparator<? super T> comparator)
If this sequence is an `IndexedSeq`, a binary search is used. Otherwise, a linear search is used.
element
- the element to findcomparator
- the comparator by which this sequence is orderedSeq<T> distinct()
Traversable
equals
.distinct
in interface Traversable<T>
Traversable
containing this elements without duplicatesSeq<T> distinctBy(Comparator<? super T> comparator)
Traversable
comparator
.distinctBy
in interface Traversable<T>
comparator
- A comparatorTraversable
containing this elements without duplicates<U> Seq<T> distinctBy(Function<? super T,? extends U> keyExtractor)
Traversable
equals
.
The elements of the result are determined in the order of their occurrence - first match wins.
distinctBy
in interface Traversable<T>
U
- key typekeyExtractor
- A key extractorTraversable
containing this elements without duplicatesSeq<T> drop(long n)
Traversable
drop
in interface Traversable<T>
n
- The number of elements to drop.Seq<T> dropRight(long n)
Traversable
dropRight
in interface Traversable<T>
n
- The number of elements to drop.Seq<T> dropUntil(Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as dropWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
dropUntil
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.Seq<T> dropWhile(Predicate<? super T> predicate)
Traversable
dropWhile
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements starting with the first.Seq<T> filter(Predicate<? super T> predicate)
Traversable
filter
in interface Traversable<T>
predicate
- A predicate<U> Seq<U> flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
Traversable
flatMap
in interface Traversable<T>
U
- The resulting component type.mapper
- A mapperdefault <U> U foldRight(U zero, BiFunction<? super T,? super U,? extends U> f)
Traversable
f
from the right,
starting with a value zero
of type B.
Example: List.of("a", "b", "c").foldRight("", (x, xs) -> x + xs) = "abc"
<C> Map<C,? extends Seq<T>> groupBy(Function<? super T,? extends C> classifier)
Traversable
groupBy
in interface Traversable<T>
C
- classified class typeclassifier
- A function which classifies elements into classesIterator<? extends Seq<T>> grouped(long size)
Traversable
Traversable
into fixed size blocks.
Let length be the length of this Iterable. Then grouped is defined as follows:
this.isEmpty()
, the resulting Iterator
is empty.size <= length
, the resulting Iterator
will contain length / size
blocks of size
size
and maybe a non-empty block of size length % size
, if there are remaining elements.size > length
, the resulting Iterator
will contain one block of size length
.
[].grouped(1) = []
[].grouped(0) throws
[].grouped(-1) throws
[1,2,3,4].grouped(2) = [[1,2],[3,4]]
[1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]]
[1,2,3,4].grouped(5) = [[1,2,3,4]]
Please note that grouped(int)
is a special case of Traversable.sliding(long, long), i.e.
grouped(size)
is the same as sliding(size, size)
.grouped
in interface Traversable<T>
size
- a positive block sizeSeq<T> init()
Traversable
init
in interface Traversable<T>
Option<? extends Seq<T>> initOption()
Traversable
Option
.initOption
in interface Traversable<T>
Some(traversable)
or None
if this is empty.<U> Seq<U> map(Function<? super T,? extends U> mapper)
Traversable
Traversable
to elements of a new type preserving their order, if any.Tuple2<? extends Seq<T>,? extends Seq<T>> partition(Predicate<? super T> predicate)
Traversable
Traversable
by splitting this elements in two in distinct tarversables
according to a predicate.partition
in interface Traversable<T>
predicate
- A predicate which classifies an element if it is in the first or the second traversable.Traversable
contains all elements that satisfy the given predicate
, the second Traversable
contains all elements that don't. The original order of elements is preserved.Seq<T> peek(Consumer<? super T> action)
Value
action
on the first element if this is an eager implementation.
Performs the given action
on all elements (the first immediately, successive deferred),
if this is a lazy implementation.Seq<T> replace(T currentElement, T newElement)
Traversable
replace
in interface Traversable<T>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Seq<T> replaceAll(T currentElement, T newElement)
Traversable
replaceAll
in interface Traversable<T>
currentElement
- An element to be substituted.newElement
- A replacement for currentElement.Seq<T> retainAll(Iterable<? extends T> elements)
Traversable
retainAll
in interface Traversable<T>
elements
- Elements to be kept.Seq<T> scan(T zero, BiFunction<? super T,? super T,? extends T> operation)
Traversable
scan
in interface Traversable<T>
zero
- neutral element for the operator opoperation
- the associative operator for the scan<U> Seq<U> scanLeft(U zero, BiFunction<? super U,? super T,? extends U> operation)
Traversable
scanLeft
in interface Traversable<T>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the element<U> Seq<U> scanRight(U zero, BiFunction<? super T,? super U,? extends U> operation)
Traversable
scanRight
in interface Traversable<T>
U
- the type of the elements in the resulting collectionzero
- the initial valueoperation
- the binary operator applied to the intermediate result and the elementIterator<? extends Seq<T>> sliding(long size)
Traversable
size
and step size 1 over this Traversable
by calling
Traversable.sliding(long, long)
.sliding
in interface Traversable<T>
size
- a positive window sizeIterator<? extends Seq<T>> sliding(long size, long step)
Traversable
size
and step
size over this Traversable
.
Examples:
[].sliding(1,1) = []
[1,2,3,4,5].sliding(2,3) = [[1,2],[4,5]]
[1,2,3,4,5].sliding(2,4) = [[1,2],[5]]
[1,2,3,4,5].sliding(2,5) = [[1,2]]
[1,2,3,4].sliding(5,3) = [[1,2,3,4],[4]]
sliding
in interface Traversable<T>
size
- a positive window sizestep
- a positive step sizeTuple2<? extends Seq<T>,? extends Seq<T>> span(Predicate<? super T> predicate)
Traversable
predicate
and the second element is the remainder.span
in interface Traversable<T>
predicate
- A predicate.Seq<T> tail()
Traversable
tail
in interface Traversable<T>
Option<? extends Seq<T>> tailOption()
Traversable
Option
.tailOption
in interface Traversable<T>
Some(traversable)
or None
if this is empty.Seq<T> take(long n)
Traversable
The result is equivalent to sublist(0, max(0, min(length(), n)))
but does not throw if n < 0
or
n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
take
in interface Traversable<T>
n
- The number of elements to take.Seq<T> takeRight(long n)
Traversable
The result is equivalent to sublist(max(0, min(length(), length() - n)), n)
, i.e. takeRight will not
throw if n < 0
or n > length()
.
In the case of n < 0
the empty instance is returned, in the case of n > length()
this is returned.
takeRight
in interface Traversable<T>
n
- The number of elements to take.Seq<T> takeUntil(Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as takeWhile(predicate.negate())
. It is intended to be used with
method references, which cannot be negated directly.
takeUntil
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.Seq<T> takeWhile(Predicate<? super T> predicate)
Traversable
takeWhile
in interface Traversable<T>
predicate
- A condition tested subsequently for the contained elements.<T1,T2> Tuple2<? extends Seq<T1>,? extends Seq<T2>> unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Traversable
unzip
in interface Traversable<T>
T1
- 1st element type of a pair returned by unzipperT2
- 2nd element type of a pair returned by unzipperunzipper
- a function which converts elements of this to pairs<T1,T2,T3> Tuple3<? extends Seq<T1>,? extends Seq<T2>,? extends Seq<T3>> unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Traversable
unzip3
in interface Traversable<T>
T1
- 1st element type of a triplet returned by unzipperT2
- 2nd element type of a triplet returned by unzipperT3
- 3rd element type of a triplet returned by unzipperunzipper
- a function which converts elements of this to pairs<U> Seq<Tuple2<T,U>> zip(Iterable<U> that)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zip
in interface Traversable<T>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.that
iterable.<U> Seq<Tuple2<T,U>> zipAll(Iterable<U> that, T thisElem, U thatElem)
Traversable
The length of the returned traversable is the maximum of the lengths of this traversable and that
iterable.
Special case: if this traversable is shorter than that elements, and that elements contains duplicates, the resulting traversable may be shorter than the maximum of the lengths of this and that because a traversable contains an element at most once.
If this Traversable is shorter than that, thisElem values are used to fill the result. If that is shorter than this Traversable, thatElem values are used to fill the result.
zipAll
in interface Traversable<T>
U
- The type of the second half of the returned pairs.that
- The Iterable providing the second half of each result pair.thisElem
- The element to be used to fill up the result if this traversable is shorter than that.thatElem
- The element to be used to fill up the result if that is shorter than this traversable.Seq<Tuple2<T,Long>> zipWithIndex()
Traversable
zipWithIndex
in interface Traversable<T>
Copyright © 2016. All Rights Reserved.