T - Component typepublic interface Seq<T> extends Traversable<T>, PartialFunction<java.lang.Integer,T>, java.io.Serializable
Basic operations:
append(Object)appendAll(Iterable)insert(int, Object)insertAll(int, Iterable)prepend(Object)prependAll(Iterable)update(int, Object)remove(Object)removeAll(Object)removeAll(Iterable)removeAt(int)removeFirst(Predicate)removeLast(Predicate)get(int)indexOf(Object)indexOf(Object, int)lastIndexOf(Object)lastIndexOf(Object, int)slice(int, int)subSequence(int)subSequence(int, int)| 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(java.lang.Iterable<? extends T> elements)
Appends all given elements to this.
|
T |
apply(java.lang.Integer index)
A
Seq is a partial function which returns the element at the specified index if the
index is valid. |
java.util.List<T> |
asJava()
Creates an immutable
List view on top of this Seq,
i.e. |
Seq<T> |
asJava(java.util.function.Consumer<? super java.util.List<T>> action)
Creates an immutable
List view on top of this Seq
that is passed to the given action. |
java.util.List<T> |
asJavaMutable()
Creates a mutable
List view on top of this Seq,
i.e. |
Seq<T> |
asJavaMutable(java.util.function.Consumer<? super java.util.List<T>> action)
Creates a mutable
List view on top of this Seq
that is passed to the given action. |
PartialFunction<java.lang.Integer,T> |
asPartialFunction()
Turns this
Seq into a PartialFunction which is defined at a specific index, if this Seq
contains at least index + 1 elements. |
<R> Seq<R> |
collect(PartialFunction<? super T,? extends R> partialFunction)
Collects all elements that are in the domain of the given
partialFunction by mapping the elements to type R. |
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(java.lang.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(java.lang.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(java.util.Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
<U> Seq<T> |
distinctBy(java.util.function.Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
Seq<T> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
Seq<T> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
Seq<T> |
dropRightUntil(java.util.function.Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element, starting from the end.
|
Seq<T> |
dropRightWhile(java.util.function.Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element, starting from the end.
|
Seq<T> |
dropUntil(java.util.function.Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
Seq<T> |
dropWhile(java.util.function.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(java.util.function.Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
Seq<T> |
filterNot(java.util.function.Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.
|
<U> Seq<U> |
flatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
default <U> U |
foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> f)
Folds this elements from the right, starting with
zero and successively calling combine. |
default T |
get(int index)
Returns the element at the specified index.
|
default Option<T> |
getOption(int index)
Returns an optional value, which may element at the specified index, or be empty
if the index is invalid for this collection.
|
default T |
getOrElse(int index,
T defaultValue)
Returns the element at the specified index, or the default value you give if
the index is invalid for this collection.
|
Seq<? extends Seq<T>> |
group()
Groups subsequent equal elements.
|
<C> Map<C,? extends Seq<T>> |
groupBy(java.util.function.Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<? extends Seq<T>> |
grouped(int 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 Option<java.lang.Integer> |
indexOfOption(T element)
Returns the index of the first occurrence of the given element as an
Option |
default Option<java.lang.Integer> |
indexOfOption(T element,
int from)
Returns the index of the first occurrence of the given element,
after or at some start index as an
Option |
default int |
indexOfSlice(java.lang.Iterable<? extends T> that)
Finds first index where this sequence contains a given sequence as a slice.
|
int |
indexOfSlice(java.lang.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 Option<java.lang.Integer> |
indexOfSliceOption(java.lang.Iterable<? extends T> that)
Finds first index where this sequence contains a given sequence as an
Option of a slice. |
default Option<java.lang.Integer> |
indexOfSliceOption(java.lang.Iterable<? extends T> that,
int from)
Finds first index after or at a start index where this sequence contains a given sequence as an
Option of a slice. |
default int |
indexWhere(java.util.function.Predicate<? super T> predicate)
Finds index of first element satisfying some predicate.
|
int |
indexWhere(java.util.function.Predicate<? super T> predicate,
int from)
Finds index of the first element satisfying some predicate after or at
some start index.
|
default Option<java.lang.Integer> |
indexWhereOption(java.util.function.Predicate<? super T> predicate)
Finds index of first element satisfying some predicate as an
Option. |
default Option<java.lang.Integer> |
indexWhereOption(java.util.function.Predicate<? super T> predicate,
int from)
Finds index of the first element satisfying some predicate after or at
some start index as an
Option. |
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,
java.lang.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 boolean |
isSequential()
Checks if the elements of this Traversable appear in encounter order.
|
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 Option<java.lang.Integer> |
lastIndexOfOption(T element)
Returns the index of the last occurrence of the given element as an
Option. |
default Option<java.lang.Integer> |
lastIndexOfOption(T element,
int end)
Returns the index of the last occurrence of the given element before or at a given end index as an
Option. |
default int |
lastIndexOfSlice(java.lang.Iterable<? extends T> that)
Finds last index where this sequence contains a given sequence as a slice.
|
int |
lastIndexOfSlice(java.lang.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 Option<java.lang.Integer> |
lastIndexOfSliceOption(java.lang.Iterable<? extends T> that)
Finds last index where this sequence contains a given sequence as a slice as an
Option. |
default Option<java.lang.Integer> |
lastIndexOfSliceOption(java.lang.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 as an
Option. |
default int |
lastIndexWhere(java.util.function.Predicate<? super T> predicate)
Finds index of last element satisfying some predicate.
|
int |
lastIndexWhere(java.util.function.Predicate<? super T> predicate,
int end)
Finds index of last element satisfying some predicate before or at given
end index.
|
default Option<java.lang.Integer> |
lastIndexWhereOption(java.util.function.Predicate<? super T> predicate)
Finds index of last element satisfying some predicate as an
Option. |
default Option<java.lang.Integer> |
lastIndexWhereOption(java.util.function.Predicate<? super T> predicate,
int end)
Finds index of last element satisfying some predicate before or at given end index as an
Option. |
Seq<T> |
leftPadTo(int length,
T element)
A copy of this sequence with an element prepended until a given target length is reached.
|
default Function1<java.lang.Integer,Option<T>> |
lift()
Deprecated.
Will be removed
|
<U> Seq<U> |
map(java.util.function.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> |
orElse(java.lang.Iterable<? extends T> other)
Returns this
Traversable if it is nonempty, otherwise return the alternative. |
Seq<T> |
orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns this
Traversable if it is nonempty, otherwise return the result of evaluating supplier. |
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(java.util.function.Predicate<? super T> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct traversables
according to a predicate. |
Seq<T> |
patch(int from,
java.lang.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(java.util.function.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(java.util.function.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(java.lang.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(java.lang.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(java.util.function.Predicate<T> predicate)
Removes the first occurrence that satisfy predicate
|
Seq<T> |
removeLast(java.util.function.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(java.lang.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> |
rotateLeft(int n)
Circular rotates the elements by the specified distance to the left direction.
|
Seq<T> |
rotateRight(int n)
Circular rotates the elements by the specified distance to the right direction.
|
Seq<T> |
scan(T zero,
java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
<U> Seq<U> |
scanLeft(U zero,
java.util.function.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,
java.util.function.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,
java.util.Comparator<? super T> comparator)
Searches this sequence for a specific element.
|
int |
segmentLength(java.util.function.Predicate<? super T> predicate,
int from)
Computes length of longest segment whose elements all satisfy some predicate.
|
Seq<T> |
shuffle()
Randomize the order of the elements in the current sequence.
|
Seq<T> |
shuffle(java.util.Random random)
Randomize the order of the elements in the current sequence using the given source
of randomness.
|
Seq<T> |
slice(int beginIndex,
int endIndex)
Returns a Seq that is a slice of this.
|
Iterator<? extends Seq<T>> |
slideBy(java.util.function.Function<? super T,?> classifier)
Slides a non-overlapping window of a variable size over this
Traversable. |
Iterator<? extends Seq<T>> |
sliding(int size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(int, int). |
Iterator<? extends Seq<T>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable. |
<U> Seq<T> |
sortBy(java.util.Comparator<? super U> comparator,
java.util.function.Function<? super T,? extends U> mapper)
Sorts this elements by comparing the elements in a different domain, using the given
mapper. |
<U extends java.lang.Comparable<? super U>> |
sortBy(java.util.function.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(java.util.Comparator<? super T> comparator)
Sorts this elements according to the provided
Comparator. |
Tuple2<? extends Seq<T>,? extends Seq<T>> |
span(java.util.function.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(int n)
Splits a Seq at the specified index.
|
Tuple2<? extends Seq<T>,? extends Seq<T>> |
splitAt(java.util.function.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(java.util.function.Predicate<? super T> predicate)
Splits a sequence at the first element which satisfies the
Predicate, e.g. |
default boolean |
startsWith(java.lang.Iterable<? extends T> that)
Tests whether this list starts with the given sequence.
|
default boolean |
startsWith(java.lang.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(int n)
Takes the first n elements of this or all elements, if this length < n.
|
Seq<T> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
Seq<T> |
takeRightUntil(java.util.function.Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element, starting from the end.
|
Seq<T> |
takeRightWhile(java.util.function.Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element, starting from the end.
|
Seq<T> |
takeUntil(java.util.function.Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
Seq<T> |
takeWhile(java.util.function.Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
Seq<T> |
update(int index,
java.util.function.Function<? super T,? extends T> updater)
Updates the given element at the specified index using the specified function.
|
Seq<T> |
update(int index,
T element)
Updates the given element at the specified index.
|
<U> Seq<Tuple2<T,U>> |
zip(java.lang.Iterable<? extends 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(java.lang.Iterable<? extends U> that,
T thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
<U,R> Seq<R> |
zipWith(java.lang.Iterable<? extends U> that,
java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
Seq<Tuple2<T,java.lang.Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
<U> Seq<U> |
zipWithIndex(java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
Zips this traversable with its indices by applying mapper provided.
|
arrangeBy, average, containsAll, count, equals, existsUnique, find, findLast, fold, foldLeft, forEachWithIndex, get, hasDefiniteSize, hashCode, head, headOption, isDistinct, isEmpty, isOrdered, isSingleValued, isTraversableAgain, iterator, last, lastOption, length, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, narrow, nonEmpty, product, reduce, reduceLeft, reduceLeftOption, reduceOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum, toLinkedMap, toMap, toSortedMap, toSortedMap, unzip, unzip3collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, isAsync, isLazy, narrow, out, out, stderr, stdout, stringPrefix, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toString, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVectorisDefinedAtstatic 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>.Seq<T> append(T element)
element - An elementSeq<T> appendAll(java.lang.Iterable<? extends T> elements)
elements - An Iterable of elementsjava.lang.NullPointerException - if elements is nullT apply(java.lang.Integer index)
Seq is a partial function which returns the element at the specified index if the
index is valid. It's up to the caller to make sure the index is valid (for instance through
isDefinedAt).
The behaviour is undefined if the index is out of bounds.
It may throw any RuntimeException or return an arbitrary value.java.util.List<T> asJava()
List view on top of this Seq,
i.e. calling mutators will result in UnsupportedOperationException at runtime.
The difference to conversion methods toJava*() is that
java.util.List view throws UnsupportedOperationException before
checking method arguments. Java does handle this case inconsistently.Collection view on this Traversable.Seq<T> asJava(java.util.function.Consumer<? super java.util.List<T>> action)
List view on top of this Seq
that is passed to the given action.action - A side-effecting unit of work that operates on an immutable java.util.List view.asJava()java.util.List<T> asJavaMutable()
List view on top of this Seq,
i.e. all mutator methods of the List are implemented.Collection view on this Traversable.asJava()Seq<T> asJavaMutable(java.util.function.Consumer<? super java.util.List<T>> action)
List view on top of this Seq
that is passed to the given action.action - A side-effecting unit of work that operates on a mutable java.util.List view.java.util.List view or a new instance of this type, if write operations are performed on the java.util.List view.asJavaMutable()PartialFunction<java.lang.Integer,T> asPartialFunction() throws java.lang.IndexOutOfBoundsException
Seq into a PartialFunction which is defined at a specific index, if this Seq
contains at least index + 1 elements. When applied to a defined index, the partial function will return
the value of this Seq at the specified index.PartialFunctionjava.lang.IndexOutOfBoundsException - if this is empty, index < 0 or index >= length()<R> Seq<R> collect(PartialFunction<? super T,? extends R> partialFunction)
TraversablepartialFunction by mapping the elements to type R.
More specifically, for each of this elements in iteration order first it is checked
partialFunction.isDefinedAt(element)
If the elements makes it through that filter, the mapped instance is added to the result collection
R newElement = partialFunction.apply(element)
Note:If this Traversable is ordered (i.e. extends Ordered,
the caller of collect has to ensure that the elements are comparable (i.e. extend Comparable).collect in interface Traversable<T>R - The new element typepartialFunction - A function that is not necessarily defined of all elements of this traversable.Traversable instance containing elements of type RSeq<? 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(java.lang.Iterable<? extends T> that)
Note: may not terminate for infinite sequences.
that - the sequence to testjava.lang.NullPointerException - 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();
thisIterator<? 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);
Cartesian power of negative value will return empty iterator.
Example:
// = ()
CharSeq.rangeClosed('A', 'Z').crossProduct(-1);
power - the number of cartesian multiplicationsdefault <U> Iterator<Tuple2<T,U>> crossProduct(java.lang.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 thatjava.lang.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 testdefault T get(int index)
index - an indexjava.lang.IndexOutOfBoundsException - if this is empty, index < 0 or index >= length()default Option<T> getOption(int index)
index - an indexdefault T getOrElse(int index, T defaultValue)
index - an indexdefaultValue - a default value to use if the index is invalid for this collection.default int indexOf(T element)
element - an elementdefault Option<java.lang.Integer> indexOfOption(T element)
Optionelement - an elementSome(index) or None if not found.int indexOf(T element, int from)
element - an elementfrom - start indexdefault Option<java.lang.Integer> indexOfOption(T element, int from)
Optionelement - an elementfrom - start indexSome(index) or None if not found.default int indexOfSlice(java.lang.Iterable<? extends T> that)
Note: may not terminate for infinite sequences.
that - the sequence to testjava.lang.NullPointerException - if that is null.default Option<java.lang.Integer> indexOfSliceOption(java.lang.Iterable<? extends T> that)
Option of a slice.
Note: may not terminate for infinite sequences.
that - the sequence to testSome(index) or None if not found.int indexOfSlice(java.lang.Iterable<? extends T> that, int from)
that - the sequence to testfrom - the start indexjava.lang.NullPointerException - if that is null.default Option<java.lang.Integer> indexOfSliceOption(java.lang.Iterable<? extends T> that, int from)
Option of a slice.
Note: may not terminate for infinite sequences.that - the sequence to testfrom - the start indexSome(index) or None if not found.default int indexWhere(java.util.function.Predicate<? super T> predicate)
predicate - the predicate used to test elements.predicate, or -1, if none exists.default Option<java.lang.Integer> indexWhereOption(java.util.function.Predicate<? super T> predicate)
Option.predicate - the predicate used to test elements.Some(index) or None if not found.int indexWhere(java.util.function.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.default Option<java.lang.Integer> indexWhereOption(java.util.function.Predicate<? super T> predicate, int from)
Option.predicate - the predicate used to test elements.from - the start indexSome(index) or None if not found.Seq<T> insert(int index, T element)
index - an indexelement - an elementjava.lang.IndexOutOfBoundsException - if this is empty, index < 0 or index >= length()Seq<T> insertAll(int index, java.lang.Iterable<? extends T> elements)
index - an indexelements - An Iterable of elementsjava.lang.IndexOutOfBoundsException - 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 indexjava.lang.IndexOutOfBoundsException - if index < 0 or index > length()default int lastIndexOf(T element)
element - an elementdefault Option<java.lang.Integer> lastIndexOfOption(T element)
Option.element - an elementSome(index) or None if not found.default int lastIndexWhere(java.util.function.Predicate<? super T> predicate)
predicate - the predicate used to test elements.predicate, or -1,
if none exists.default Option<java.lang.Integer> lastIndexWhereOption(java.util.function.Predicate<? super T> predicate)
Option.predicate - the predicate used to test elements.Some(index) or None if not found.int lastIndexWhere(java.util.function.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.default Option<java.lang.Integer> lastIndexWhereOption(java.util.function.Predicate<? super T> predicate, int end)
Option.predicate - the predicate used to test elements.end - the maximum index of the searchSome(index) or None if not found.@Deprecated default Function1<java.lang.Integer,Option<T>> lift()
lift in interface PartialFunction<java.lang.Integer,T>int lastIndexOf(T element, int end)
element - an elementend - the end indexdefault Option<java.lang.Integer> lastIndexOfOption(T element, int end)
Option.element - an elementend - the end indexSome(index) or None if not found.default int lastIndexOfSlice(java.lang.Iterable<? extends T> that)
Note: will not terminate for infinite sequences.
that - the sequence to testjava.lang.NullPointerException - if that is null.default Option<java.lang.Integer> lastIndexOfSliceOption(java.lang.Iterable<? extends T> that)
Option.that - the sequence to testSome(index) or None if not found.int lastIndexOfSlice(java.lang.Iterable<? extends T> that, int end)
that - the sequence to testend - the end indexjava.lang.NullPointerException - if that is null.default Option<java.lang.Integer> lastIndexOfSliceOption(java.lang.Iterable<? extends T> that, int end)
Option.that - the sequence to testend - the end indexSome(index) or None if not found.Seq<T> padTo(int length, T element)
Note: lazily-evaluated Seq implementations need to process all elements in order to gather the overall length.
length - the target lengthelement - the padding elementelement so that the resulting sequence has a length of at least length.Seq<T> leftPadTo(int length, T element)
Note: lazily-evaluated Seq implementations need to process all elements in order to gather the overall length.
length - the target lengthelement - the padding elementelement so that the resulting sequence has a length of at least length.Seq<T> patch(int from, java.lang.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(java.util.function.Predicate<? super T> predicate)
predicate - the predicate used to test elements.Seq<T> prepend(T element)
element - An elementSeq<T> prependAll(java.lang.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(java.lang.Iterable<? extends T> elements)
elements - Elements to be removed from this Seq.java.lang.NullPointerException - if elements is nullSeq<T> removeAt(int index)
index - position of element to removejava.lang.IndexOutOfBoundsException - if this is empty, index < 0 or index >= length()Seq<T> removeFirst(java.util.function.Predicate<T> predicate)
predicate - an predicateSeq<T> removeLast(java.util.function.Predicate<T> predicate)
predicate - an predicateIterator<T> reverseIterator()
Note: xs.reverseIterator() is the same as xs.reverse().iterator() but might
be more efficient.
Seq<T> rotateLeft(int n)
// = List(3, 4, 5, 1, 2)
List.of(1, 2, 3, 4, 5).rotateLeft(2);
n - distance of left rotationSeq<T> rotateRight(int n)
// = List(4, 5, 1, 2, 3)
List.of(1, 2, 3, 4, 5).rotateRight(2);
n - distance of right rotationint segmentLength(java.util.function.Predicate<? super T> predicate, int from)
Note: may not terminate for infinite sequences.
predicate - the predicate used to test elements.from - the index where the search starts.Seq<T> shuffle()
Seq<T> shuffle(java.util.Random random)
random - A random number generatorSeq<T> slice(int beginIndex, int 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.java.lang.ClassCastException - if this elements are not ComparableSeq<T> sorted(java.util.Comparator<? super T> comparator)
Comparator. If this elements are not
Comparable, a java.lang.ClassCastException may be thrown.comparator - A comparator<U extends java.lang.Comparable<? super U>> Seq<T> sortBy(java.util.function.Function<? super T,? extends U> mapper)
mapper.U - The domain where elements are comparedmapper - A mapperjava.lang.NullPointerException - if mapper is null<U> Seq<T> sortBy(java.util.Comparator<? super U> comparator, java.util.function.Function<? super T,? extends U> mapper)
mapper.U - The domain where elements are comparedcomparator - A comparatormapper - A mapperjava.lang.NullPointerException - if comparator or mapper is nullTuple2<? extends Seq<T>,? extends Seq<T>> splitAt(int n)
splitAt(n) is equivalent to
Tuple.of(take(n), drop(n)).n - An index.Tuple containing the first n and the remaining elements.Tuple2<? extends Seq<T>,? extends Seq<T>> splitAt(java.util.function.Predicate<? super T> predicate)
Predicate, e.g. Tuple(init, element+tail).predicate - An predicateTuple containing divided sequencesTuple2<? extends Seq<T>,? extends Seq<T>> splitAtInclusive(java.util.function.Predicate<? super T> predicate)
Predicate, e.g. Tuple(init+element, tail).predicate - An predicateTuple containing divided sequencesdefault boolean startsWith(java.lang.Iterable<? extends T> that)
that - the sequence to testdefault boolean startsWith(java.lang.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(int) which is similar but does not throw.beginIndex - the beginning index, inclusivejava.lang.IndexOutOfBoundsException - 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(int, int) which returns an empty sequence instead of throwing.beginIndex - the beginning index, inclusiveendIndex - the end index, exclusivejava.lang.IndexOutOfBoundsException - if beginIndex or endIndex is negative or
if endIndex is greater than length()java.lang.IllegalArgumentException - if beginIndex is greater than endIndexSeq<T> update(int index, T element)
index - an indexelement - an elementjava.lang.IndexOutOfBoundsException - if this is empty, index < 0 or index >= length()Seq<T> update(int index, java.util.function.Function<? super T,? extends T> updater)
index - an indexupdater - a function transforming the previous valuejava.lang.IndexOutOfBoundsException - 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 find(-(insertion point) - 1). The
insertion point is defined as the point at which the
element would be inserted into the sequence. Note that this guarantees that
the return value will be >= 0 if and only if the element is found.java.lang.ClassCastException - if T cannot be cast to Comparable<? super T>int search(T element, java.util.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 ordered(-(insertion point) - 1). The
insertion point is defined as the point at which the
element would be inserted into the sequence. Note that this guarantees that
the return value will be >= 0 if and only if the element is found.Seq<T> distinct()
Traversableequals.distinct in interface Traversable<T>Traversable containing this elements without duplicatesSeq<T> distinctBy(java.util.Comparator<? super T> comparator)
Traversablecomparator.distinctBy in interface Traversable<T>comparator - A comparatorTraversable containing this elements without duplicates<U> Seq<T> distinctBy(java.util.function.Function<? super T,? extends U> keyExtractor)
Traversableequals.
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(int n)
Traversabledrop in interface Traversable<T>n - The number of elements to drop.Seq<T> dropUntil(java.util.function.Predicate<? super T> predicate)
TraversabledropUntil in interface Traversable<T>predicate - A condition tested subsequently for this elements.Seq<T> dropWhile(java.util.function.Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as dropUntil(predicate.negate()).
It is intended to be used with method references, which cannot be negated directly.
dropWhile in interface Traversable<T>predicate - A condition tested subsequently for this elements.Seq<T> dropRight(int n)
TraversabledropRight in interface Traversable<T>n - The number of elements to drop.Seq<T> dropRightUntil(java.util.function.Predicate<? super T> predicate)
predicate - A condition tested subsequently for this elements, starting from the end.java.lang.NullPointerException - if predicate is nullSeq<T> dropRightWhile(java.util.function.Predicate<? super T> predicate)
Note: This is essentially the same as dropRightUntil(predicate.negate()).
It is intended to be used with method references, which cannot be negated directly.
predicate - A condition tested subsequently for this elements, starting from the end.java.lang.NullPointerException - if predicate is nullSeq<T> filter(java.util.function.Predicate<? super T> predicate)
Traversablefilter in interface Traversable<T>predicate - A predicateSeq<T> filterNot(java.util.function.Predicate<? super T> predicate)
TraversableThe default implementation is equivalent to
filter(predicate.negate()filterNot in interface Traversable<T>predicate - A predicate<U> Seq<U> flatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
TraversableflatMap in interface Traversable<T>U - The resulting component type.mapper - A mapperdefault <U> U foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> f)
Traversablezero and successively calling combine.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
Seq<? extends Seq<T>> group()
<C> Map<C,? extends Seq<T>> groupBy(java.util.function.Function<? super T,? extends C> classifier)
TraversablegroupBy in interface Traversable<T>C - classified class typeclassifier - A function which classifies elements into classesTraversable.arrangeBy(Function)Iterator<? extends Seq<T>> grouped(int size)
TraversableTraversable 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(int, int), i.e.
grouped(size) is the same as sliding(size, size).grouped in interface Traversable<T>size - a positive block sizeSeq<T> init()
Traversableinit in interface Traversable<T>Option<? extends Seq<T>> initOption()
TraversableOption.initOption in interface Traversable<T>Some(traversable) or None if this is empty.<U> Seq<U> map(java.util.function.Function<? super T,? extends U> mapper)
TraversableTraversable to elements of a new type preserving their order, if any.Seq<T> orElse(java.lang.Iterable<? extends T> other)
TraversableTraversable if it is nonempty, otherwise return the alternative.orElse in interface Traversable<T>other - An alternative TraversableTraversable if it is nonempty, otherwise return the alternative.Seq<T> orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
TraversableTraversable if it is nonempty, otherwise return the result of evaluating supplier.orElse in interface Traversable<T>supplier - An alternative Traversable supplierTraversable if it is nonempty, otherwise return the result of evaluating supplier.Tuple2<? extends Seq<T>,? extends Seq<T>> partition(java.util.function.Predicate<? super T> predicate)
TraversableTraversable by splitting this elements in two in distinct traversables
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(java.util.function.Consumer<? super T> action)
Valueaction 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)
Traversablereplace in interface Traversable<T>currentElement - An element to be substituted.newElement - A replacement for currentElement.Seq<T> replaceAll(T currentElement, T newElement)
TraversablereplaceAll in interface Traversable<T>currentElement - An element to be substituted.newElement - A replacement for currentElement.Seq<T> retainAll(java.lang.Iterable<? extends T> elements)
TraversableretainAll in interface Traversable<T>elements - Elements to be kept.Seq<T> scan(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Traversablescan in interface Traversable<T>zero - neutral element for the operator opoperation - the associative operator for the scan<U> Seq<U> scanLeft(U zero, java.util.function.BiFunction<? super U,? super T,? extends U> operation)
TraversablescanLeft 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, java.util.function.BiFunction<? super T,? super U,? extends U> operation)
TraversablescanRight 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>> slideBy(java.util.function.Function<? super T,?> classifier)
TraversableTraversable.
Each window contains elements with the same class, as determined by classifier. Two consecutive
values in this Traversable will be in the same window only if classifier returns equal
values for them. Otherwise, the values will constitute the last element of the previous window and the
first element of the next window.
Examples:
[].slideBy(Function.identity()) = []
[1,2,3,4,4,5].slideBy(Function.identity()) = [[1],[2],[3],[4,4],[5]]
[1,2,3,10,12,5,7,20,29].slideBy(x -> x/10) = [[1,2,3],[10,12],[5,7],[20,29]]
slideBy in interface Traversable<T>classifier - A function which classifies elements into classesIterator<? extends Seq<T>> sliding(int size)
Traversablesize and step size 1 over this Traversable by calling
Traversable.sliding(int, int).sliding in interface Traversable<T>size - a positive window sizeIterator<? extends Seq<T>> sliding(int size, int step)
Traversablesize 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]]
sliding in interface Traversable<T>size - a positive window sizestep - a positive step sizeTuple2<? extends Seq<T>,? extends Seq<T>> span(java.util.function.Predicate<? super T> predicate)
Traversablepredicate and the second element is the remainder.span in interface Traversable<T>predicate - A predicate.Tuple containing the longest prefix of elements that satisfy p and the remainder.Seq<T> tail()
Traversabletail in interface Traversable<T>Option<? extends Seq<T>> tailOption()
TraversableOption.tailOption in interface Traversable<T>Some(traversable) or None if this is empty.Seq<T> take(int 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> takeUntil(java.util.function.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(java.util.function.Predicate<? super T> predicate)
TraversabletakeWhile in interface Traversable<T>predicate - A condition tested subsequently for the contained elements.Seq<T> takeRight(int 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> takeRightUntil(java.util.function.Predicate<? super T> predicate)
predicate - A condition tested subsequently for this elements, starting from the end.java.lang.NullPointerException - if predicate is nullSeq<T> takeRightWhile(java.util.function.Predicate<? super T> predicate)
Note: This is essentially the same as takeRightUntil(predicate.negate()).
It is intended to be used with method references, which cannot be negated directly.
predicate - A condition tested subsequently for this elements, starting from the end.java.lang.NullPointerException - if predicate is null<U> Seq<Tuple2<T,U>> zip(java.lang.Iterable<? extends 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,R> Seq<R> zipWith(java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWith in interface Traversable<T>U - The type of the second parameter of the mapper.R - The type of the mapped elements.that - The Iterable providing the second parameter of the mapper.mapper - a mapper.that iterable.<U> Seq<Tuple2<T,U>> zipAll(java.lang.Iterable<? extends 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,java.lang.Integer>> zipWithIndex()
TraversablezipWithIndex in interface Traversable<T><U> Seq<U> zipWithIndex(java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
TraversablezipWithIndex in interface Traversable<T>U - The type of the mapped elements.mapper - a mapper.default boolean isSequential()
TraversableisSequential in interface Traversable<T>