T
- Component typepublic interface Seq<T> extends Traversable<T>, Function1<Integer,T>, 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 | Interface and Description |
---|---|
static interface |
Lambda.Memoized
Zero Abstract Method (ZAM) interface for marking functions as memoized using intersection types.
|
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). |
List<T> |
asJava()
Creates an immutable
List view on top of this Seq ,
i.e. |
Seq<T> |
asJava(Consumer<? super List<T>> action)
|
List<T> |
asJavaMutable()
Creates a mutable
List view on top of this Seq ,
i.e. |
Seq<T> |
asJavaMutable(Consumer<? super List<T>> action)
|
<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(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(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(Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element, starting from the end.
|
Seq<T> |
dropRightWhile(Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element, starting from the end.
|
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)
Folds this elements from the right, starting with
zero and successively calling combine . |
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(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<Integer> |
indexOfOption(T element)
Returns the index of the first occurrence of the given element as an
Option |
default Option<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(Iterable<? extends T> that)
Finds first index where this sequence contains a given sequence as a slice.
|
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 Option<Integer> |
indexOfSliceOption(Iterable<? extends T> that)
Finds first index where this sequence contains a given sequence as an
Option of a slice. |
default Option<Integer> |
indexOfSliceOption(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(Predicate<? super T> predicate)
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.
|
default Option<Integer> |
indexWhereOption(Predicate<? super T> predicate)
Finds index of first element satisfying some predicate as an
Option . |
default Option<Integer> |
indexWhereOption(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,
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 |
isMemoized()
Checks if this function is memoizing (= caching) computed values.
|
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<Integer> |
lastIndexOfOption(T element)
Returns the index of the last occurrence of the given element as an
Option . |
default Option<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(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 Option<Integer> |
lastIndexOfSliceOption(Iterable<? extends T> that)
Finds last index where this sequence contains a given sequence as a slice as an
Option . |
default Option<Integer> |
lastIndexOfSliceOption(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(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.
|
default Option<Integer> |
lastIndexWhereOption(Predicate<? super T> predicate)
Finds index of last element satisfying some predicate as an
Option . |
default Option<Integer> |
lastIndexWhereOption(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<Integer,Option<T>> |
lift()
Turns this sequence into a plain function returning an Option result.
|
<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> |
orElse(Iterable<? extends T> other)
Returns this
Traversable if it is nonempty, otherwise return the alternative. |
Seq<T> |
orElse(Supplier<? extends 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(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,
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(Predicate<? super T> predicate)
Returns a new Seq consisting of all elements which do not satisfy the given predicate.
|
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> |
shuffle()
Randomize the order of the elements in the current sequence.
|
Seq<T> |
slice(int beginIndex,
int endIndex)
Returns a Seq that is a slice of this.
|
Iterator<? extends Seq<T>> |
slideBy(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(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(int 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(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> |
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.
|
<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,
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.
|
default Function1<Integer,T> |
withDefault(Function<? super Integer,? extends T> defaultFunction)
Turns this sequence from a partial function into a total function that
returns a value computed by defaultFunction for all indexes that are out of bounds.
|
default Function1<Integer,T> |
withDefaultValue(T defaultValue)
Turns this sequence from a partial function into a total function that
returns defaultValue for all indexes that are out of bounds.
|
<U> Seq<Tuple2<T,U>> |
zip(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(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(Iterable<? extends U> that,
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,Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
<U> Seq<U> |
zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
arrangeBy, average, containsAll, count, equals, existsUnique, find, findLast, foldLeft, 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, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
fold, reduce, reduceOption
collect, 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, 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, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
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>
.Seq<T> append(T element)
element
- An elementSeq<T> appendAll(Iterable<? extends T> elements)
elements
- An Iterable of elementsNullPointerException
- if elements
is nulldefault T apply(Integer index)
Seq
is a partial function which returns the element at the specified index by calling
get(int).@GwtIncompatible 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
.@GwtIncompatible Seq<T> asJava(Consumer<? super List<T>> action)
action
- A side-effecting unit of work that operates on an immutable java.util.List
view.asJava()
@GwtIncompatible 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()
@GwtIncompatible Seq<T> asJavaMutable(Consumer<? super List<T>> 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()
<R> Seq<R> collect(PartialFunction<? super T,? extends R> partialFunction)
Traversable
partialFunction
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 R
Seq<? 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 sequences.
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);
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(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 elementdefault Option<Integer> indexOfOption(T element)
Option
element
- an elementSome(index)
or None
if not found.int indexOf(T element, int from)
element
- an elementfrom
- start indexdefault Option<Integer> indexOfOption(T element, int from)
Option
element
- an elementfrom
- start indexSome(index)
or None
if not found.default int indexOfSlice(Iterable<? extends T> that)
Note: may not terminate for infinite sequences.
that
- the sequence to testNullPointerException
- if that
is null.default Option<Integer> indexOfSliceOption(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(Iterable<? extends T> that, int from)
that
- the sequence to testfrom
- the start indexNullPointerException
- if that
is null.default Option<Integer> indexOfSliceOption(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(Predicate<? super T> predicate)
predicate
- the predicate used to test elements.predicate
, or -1
, if none exists.default Option<Integer> indexWhereOption(Predicate<? super T> predicate)
Option
.predicate
- the predicate used to test elements.Some(index)
or None
if not found.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.default Option<Integer> indexWhereOption(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 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 Option<Integer> lastIndexOfOption(T element)
Option
.element
- an elementSome(index)
or None
if not found.default int lastIndexWhere(Predicate<? super T> predicate)
predicate
- the predicate used to test elements.predicate
, or -1
,
if none exists.default Option<Integer> lastIndexWhereOption(Predicate<? super T> predicate)
Option
.predicate
- the predicate used to test elements.Some(index)
or None
if not found.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.default Option<Integer> lastIndexWhereOption(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.default Function1<Integer,Option<T>> lift()
int lastIndexOf(T element, int end)
element
- an elementend
- the end indexdefault Option<Integer> lastIndexOfOption(T element, int end)
Option
.element
- an elementend
- the end indexSome(index)
or None
if not found.default int lastIndexOfSlice(Iterable<? extends T> that)
Note: will not terminate for infinite sequences.
that
- the sequence to testNullPointerException
- if that
is null.default Option<Integer> lastIndexOfSliceOption(Iterable<? extends T> that)
Option
.that
- the sequence to testSome(index)
or None
if not found.int lastIndexOfSlice(Iterable<? extends T> that, int end)
that
- the sequence to testend
- the end indexNullPointerException
- if that
is null.default Option<Integer> lastIndexOfSliceOption(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, 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> removeAll(Predicate<? super T> predicate)
predicate
- the predicate used to test elementsNullPointerException
- if predicate
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)
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> 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.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 mapperNullPointerException
- if mapper
is null<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 mapperNullPointerException
- 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(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(int)
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(int, int)
which returns an empty sequence instead of throwing.beginIndex
- the beginning index, inclusiveendIndex
- the end index, exclusiveIndexOutOfBoundsException
- if beginIndex
or endIndex
is negative or
if endIndex
is greater than length()
IllegalArgumentException
- 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()Seq<T> update(int index, Function<? super T,? extends T> updater)
index
- an indexupdater
- a function transforming the previous valueIndexOutOfBoundsException
- 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(int n)
Traversable
drop
in interface Traversable<T>
n
- The number of elements to drop.Seq<T> dropUntil(Predicate<? super T> predicate)
Traversable
dropUntil
in interface Traversable<T>
predicate
- A condition tested subsequently for this elements.Seq<T> dropWhile(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)
Traversable
dropRight
in interface Traversable<T>
n
- The number of elements to drop.Seq<T> dropRightUntil(Predicate<? super T> predicate)
predicate
- A condition tested subsequently for this elements, starting from the end.NullPointerException
- if predicate
is nullSeq<T> dropRightWhile(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.NullPointerException
- if predicate
is nullSeq<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)
Foldable
zero
and successively calling combine
.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
<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 classesTraversable.arrangeBy(Function)
Iterator<? extends Seq<T>> grouped(int 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(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()
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.Seq<T> orElse(Iterable<? extends T> other)
Traversable
Traversable
if it is nonempty, otherwise return the alternative.orElse
in interface Traversable<T>
other
- An alternative Traversable
Traversable
if it is nonempty, otherwise return the alternative.Seq<T> orElse(Supplier<? extends Iterable<? extends T>> supplier)
Traversable
Traversable
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(Predicate<? super T> predicate)
Traversable
Traversable
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(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>> slideBy(Function<? super T,?> classifier)
Traversable
Traversable
.
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)
Traversable
size
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)
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.Tuple
containing the longest prefix of elements that satisfy p and the remainder.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(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> 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> 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<? 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(Iterable<? extends U> that, 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(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,Integer>> zipWithIndex()
Traversable
zipWithIndex
in interface Traversable<T>
<U> Seq<U> zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWithIndex
in interface Traversable<T>
U
- The type of the mapped elements.mapper
- a mapper.that
iterable.default Function1<Integer,T> withDefaultValue(T defaultValue)
defaultValue
- default value to return for out of bound indexesdefault Function1<Integer,T> withDefault(Function<? super Integer,? extends T> defaultFunction)
defaultFunction
- function to evaluate for all out of bounds indexes.default boolean isSequential()
Traversable
isSequential
in interface Traversable<T>
default boolean isMemoized()
Copyright © 2019. All Rights Reserved.