Interface Seq<T>
- Type Parameters:
T- the element type
- All Superinterfaces:
Foldable<T>,Function<Integer,,T> Function1<Integer,,T> Iterable<T>,PartialFunction<Integer,,T> Serializable,Traversable<T>,Value<T>
- All Known Subinterfaces:
IndexedSeq<T>,LinearSeq<T>,List<T>,Stream<T>
- All Known Implementing Classes:
Array,CharSeq,List.Cons,List.Nil,Queue,Stream.Cons,Stream.Empty,StreamModule.AppendElements,StreamModule.ConsImpl,Vector
Sequences built on this interface support a broad set of operations, including element insertion and removal, indexed access, slicing, filtering, sorting, zipping, and various combinatorial transformations such as permutations, combinations, and cross-products. Most operations return a new sequence while retaining the original ordering semantics.
The interface also provides mechanisms for traversal, conversion to Java collection views (both read-only and mutable), and treating the sequence as an index-based partial function.
Views:-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe serial version UID for serialization. -
Method Summary
Modifier and TypeMethodDescriptionReturns a new sequence with the given element appended at the end.Returns a new sequence with all elements from the givenIterableappended at the end of this sequence.default TDeprecated.Will be removedasJava()Returns an immutableListview of thisSeq.Returns a mutableListview of thisSeq.asJavaMutable(@NonNull Consumer<? super List<T>> action) Returns aPartialFunctionview of thisSeq, where the function is defined at an index if this sequence contains at leastindex + 1elements.<R> Seq<R> collect(@NonNull PartialFunction<? super T, ? extends R> partialFunction) Applies aPartialFunctionto all elements that are defined for it and collects the results.Returns a sequence containing all combinations of elements from this sequence, for all sizes from0tolength().combinations(int k) Returns all subsets of this sequence containing exactlykdistinct elements, i.e., the k-combinations of this sequence.default booleancontainsSlice(@NonNull Iterable<? extends T> that) Checks whether this sequence contains the given sequence as a contiguous slice.Computes the Cartesian product of this sequence with itself, producing all pairs of elements (this × this).crossProduct(int power) Returns the n-ary Cartesian power (cross product) of this sequence.crossProduct(@NonNull Iterable<? extends U> that) Computes the Cartesian product of this sequence with another iterable, producing pairs of elements (this × that).distinct()Returns a newTraversablecontaining the elements of this instance with all duplicates removed.distinctBy(@NonNull Comparator<? super T> comparator) Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.distinctBy(@NonNull Function<? super T, ? extends U> keyExtractor) Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.distinctByKeepLast(@NonNull Comparator<? super T> comparator) Returns a sequence with duplicate elements removed, as determined by the provided comparator.distinctByKeepLast(@NonNull Function<? super T, ? extends U> keyExtractor) Returns a sequence with duplicates removed based on a key extracted from each element.drop(int n) Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.dropRight(int n) Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.dropRightUntil(@NonNull Predicate<? super T> predicate) Drops elements from the end of the sequence until an element satisfies the given predicate.dropRightWhile(@NonNull Predicate<? super T> predicate) Drops elements from the end of the sequence while the given predicate holds.Returns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.default booleanChecks whether this sequence ends with the given sequence.Returns a new traversable containing only the elements that satisfy the given predicate.<U> Seq<U> Transforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.default <U> UfoldRight(U zero, @NonNull BiFunction<? super T, ? super U, ? extends U> f) Folds the elements of this structure from the right, starting with the givenzerovalue and successively applying thecombinefunction to each element.get(int index) Returns the element at the specified index.Groups elements of thisTraversablebased on a classifier function.grouped(int size) Splits thisTraversableinto consecutive blocks of the given size.default intReturns the index of the first occurrence of the given element, or-1if this sequence does not contain the element.intReturns the index of the first occurrence of the given element, starting at the specified index, or-1if this sequence does not contain the element.indexOfOption(T element) Returns the index of the first occurrence of the given element as anOption.indexOfOption(T element, int from) Returns the index of the first occurrence of the given element at or after the specified start index, as anOption.default intindexOfSlice(@NonNull Iterable<? extends T> that) Returns the first index at which this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.intindexOfSlice(@NonNull Iterable<? extends T> that, int from) Returns the first index at or after the specified start index where this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.indexOfSliceOption(@NonNull Iterable<? extends T> that) Returns the first index at which this sequence contains the given sequence as a contiguous slice, wrapped in anOption.indexOfSliceOption(@NonNull Iterable<? extends T> that, int from) Returns the first index at or after the specified start index where this sequence contains the given sequence as a contiguous slice, wrapped in anOption.default intindexWhere(@NonNull Predicate<? super T> predicate) Returns the index of the first element in this sequence that satisfies the given predicate, or-1if no such element exists.intindexWhere(@NonNull Predicate<? super T> predicate, int from) Returns the index of the first element at or after the specified start index that satisfies the given predicate, or-1if no such element exists.indexWhereOption(@NonNull Predicate<? super T> predicate) Returns the index of the first element satisfying the given predicate as anOption.indexWhereOption(@NonNull Predicate<? super T> predicate, int from) Returns the index of the first element at or after the specified start index that satisfies the given predicate as anOption.init()Returns all elements of this Traversable except the last one.Returns all elements of this Traversable except the last one, wrapped in anOption.Returns a new sequence with the given element inserted at the specified index.Returns a new sequence with the given elements inserted at the specified index.intersperse(T element) Returns a new sequence where the given element is inserted between all elements of this sequence.default booleanIndicates whether the elements of this Traversable appear in encounter (insertion) order.iterator(int index) Returns an iterator over the elements of this sequence starting at the specified index.default intlastIndexOf(T element) Returns the index of the last occurrence of the given element, or-1if this sequence does not contain the element.intlastIndexOf(T element, int end) Returns the index of the last occurrence of the given element at or before the specified end index, or-1if this sequence does not contain the element.lastIndexOfOption(T element) Returns the index of the last occurrence of the given element as anOption.lastIndexOfOption(T element, int end) Returns the index of the last occurrence of the given element at or before the specified end index as anOption.default intlastIndexOfSlice(@NonNull Iterable<? extends T> that) Returns the last index where this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.intlastIndexOfSlice(@NonNull Iterable<? extends T> that, int end) Returns the last index at or before the specified end index where this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.lastIndexOfSliceOption(@NonNull Iterable<? extends T> that) Returns the last index where this sequence contains the given sequence as a contiguous slice, wrapped in anOption.lastIndexOfSliceOption(@NonNull Iterable<? extends T> that, int end) Returns the last index at or before the specified end index where this sequence contains the given sequence as a contiguous slice, wrapped in anOption.default intlastIndexWhere(@NonNull Predicate<? super T> predicate) Returns the index of the last element in this sequence that satisfies the given predicate, or-1if no such element exists.intlastIndexWhere(@NonNull Predicate<? super T> predicate, int end) Returns the index of the last element at or before the specified end index that satisfies the given predicate, or-1if no such element exists.lastIndexWhereOption(@NonNull Predicate<? super T> predicate) Returns the index of the last element satisfying the given predicate as anOption.lastIndexWhereOption(@NonNull Predicate<? super T> predicate, int end) Returns the index of the last element at or before the specified end index that satisfies the given predicate, wrapped in anOption.Returns a new sequence with this sequence padded on the left with the given element until the specified target length is reached.lift()Deprecated.Will be removed<U> Seq<U> Transforms the elements of this Traversable to a new type, preserving order if defined.default <U> Seq<U> mapTo(U value) Maps the underlying value to another fixed value.Maps the underlying value to Voidstatic <T> Seq<T> Narrows aSeq<? extends T>toSeq<T>via a safe unchecked cast.Returns thisTraversableif it is non-empty; otherwise, returns the given alternative.Returns thisTraversableif it is non-empty; otherwise, returns the result of evaluating the given supplier.Returns a new sequence with this sequence padded on the right with the given element until the specified target length is reached.Splits thisTraversableinto two partitions according to a predicate.Returns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.Performs the givenactionon the first element if this is an eager implementation.Returns all unique permutations of this sequence.default intprefixLength(@NonNull Predicate<? super T> predicate) Returns the length of the longest prefix of this sequence whose elements all satisfy the given predicate.Returns a new sequence with the given element prepended to this sequence.prependAll(@NonNull Iterable<? extends T> elements) Returns a new sequence with all given elements prepended to this sequence.Returns a new traversable containing only the elements that do not satisfy the given predicate.Returns a new sequence with the first occurrence of the given element removed.Returns a new sequence with all occurrences of the given elements removed.Deprecated.Please usereject(Predicate)Returns a new sequence with all occurrences of the given element removed.removeAt(int index) Returns a new sequence with the element at the specified position removed.removeFirst(@NonNull Predicate<T> predicate) Returns a new sequence with the first element that satisfies the given predicate removed.removeLast(@NonNull Predicate<T> predicate) Returns a new sequence with the last element that satisfies the given predicate removed.Replaces the first occurrence ofcurrentElementwithnewElement, if it exists.replaceAll(T currentElement, T newElement) Replaces all occurrences ofcurrentElementwithnewElement.Retains only the elements from this Traversable that are contained in the givenelements.reverse()Returns a new sequence with the order of elements reversed.Returns an iterator that yields elements of this sequence in reversed order.rotateLeft(int n) Returns a new sequence with the elements circularly rotated to the left by the specified distance.rotateRight(int n) Returns a new sequence with the elements circularly rotated to the right by the specified distance.Computes a prefix scan of the elements of this Traversable.<U> Seq<U> scanLeft(U zero, @NonNull BiFunction<? super U, ? super T, ? extends U> operation) Produces a collection containing cumulative results of applying the operator from left to right.<U> Seq<U> scanRight(U zero, @NonNull BiFunction<? super T, ? super U, ? extends U> operation) Produces a collection containing cumulative results of applying the operator from right to left.intSearches for a specified element in this sequence, which must be sorted in ascending natural order.intsearch(T element, @NonNull Comparator<? super T> comparator) Searches for a specified element in this sequence, which must be sorted according to the given comparator.intsegmentLength(@NonNull Predicate<? super T> predicate, int from) Returns the length of the longest contiguous segment, starting from the specified index, in which all elements satisfy the given predicate.shuffle()Returns a new sequence with the elements randomly shuffled.slice(int beginIndex, int endIndex) Returns a subsequence (slice) of this sequence, starting atbeginIndex(inclusive) and ending atendIndex(exclusive).Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.sliding(int size) Slides a window of a givensizeover thisTraversablewith a step size of 1.sliding(int size, int step) Slides a window of a specificsizewith a givenstepover thisTraversable.sortBy(@NonNull Comparator<? super U> comparator, Function<? super T, ? extends U> mapper) Returns a new sequence sorted by comparing elements in a different domain defined by the givenmapper, using the providedcomparator.<U extends Comparable<? super U>>
Seq<T> Returns a new sequence sorted by comparing elements in a different domain defined by the givenmapper.sorted()Returns a new sequence with elements sorted according to their natural order.sorted(@NonNull Comparator<? super T> comparator) Returns a new sequence with elements sorted according to the givenComparator.Splits thisTraversableinto a prefix and remainder according to the givenpredicate.splitAt(int n) Splits this sequence at the specified index.Splits this sequence at the first element satisfying the given predicate.splitAtInclusive(@NonNull Predicate<? super T> predicate) Splits this sequence at the first element satisfying the given predicate, including the element in the first part.default booleanstartsWith(@NonNull Iterable<? extends T> that) Tests whether this sequence starts with the given sequence.default booleanstartsWith(@NonNull Iterable<? extends T> that, int offset) Tests whether this sequence contains the given sequence starting at the specified index.subSequence(int beginIndex) Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndexand extending to the end of this sequence.subSequence(int beginIndex, int endIndex) Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndex(inclusive) and ending atendIndex(exclusive).tail()Returns a newTraversablewithout its first element.Returns a newTraversablewithout its first element as anOption.take(int n) Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.takeRight(int n) Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.takeRightUntil(@NonNull Predicate<? super T> predicate) Takes elements from the end of the sequence until an element satisfies the given predicate.takeRightWhile(@NonNull Predicate<? super T> predicate) Takes elements from the end of the sequence while the given predicate holds.Takes elements from thisTraversableuntil the given predicate holds for an element.Takes elements from thisTraversablewhile the given predicate holds.Unzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.Unzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.Returns a newSeqwith the element at the specified index updated using the given function.Returns a newSeqwith the element at the specified index replaced by the given value.withDefault(@NonNull Function<? super Integer, ? extends T> defaultFunction) Deprecated.Will be removedwithDefaultValue(T defaultValue) Deprecated.Will be removedReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable.Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.<U,R> Seq <R> zipWith(@NonNull Iterable<? extends U> that, BiFunction<? super T, ? super U, ? extends R> mapper) Returns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function.Zips thisTraversablewith its indices, starting at 0.<U> Seq<U> zipWithIndex(@NonNull BiFunction<? super T, ? super Integer, ? extends U> mapper) Zips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.Methods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOptionMethods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupledMethods inherited from interface io.vavr.PartialFunction
isDefinedAtMethods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, equals, existsUnique, find, findLast, 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, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sumMethods inherited from interface io.vavr.Value
collect, collect, contains, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, isAsync, isLazy, 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, toVector
-
Field Details
-
serialVersionUID
static final long serialVersionUIDThe serial version UID for serialization.- See Also:
-
-
Method Details
-
narrow
Narrows aSeq<? extends T>toSeq<T>via a safe unchecked cast. This is valid becauseSeqis immutable and thus covariant in its element type.- Type Parameters:
T- the element type of the resulting sequence- Parameters:
seq- the sequence to narrow- Returns:
- the given sequence viewed as
Seq<T>
-
append
Returns a new sequence with the given element appended at the end.- Parameters:
element- the element to append- Returns:
- a new
Seqcontaining all elements of this sequence followed by the given element
-
appendAll
Returns a new sequence with all elements from the givenIterableappended at the end of this sequence.- Parameters:
elements- the elements to append; must not benull- Returns:
- a new
Seqcontaining all elements of this sequence followed by the given elements - Throws:
NullPointerException- ifelementsisnull
-
apply
Deprecated.Will be removedASeqis a partial function which returns the element at the specified index by calling get(int).- Specified by:
applyin interfaceFunction<Integer,T> - Specified by:
applyin interfaceFunction1<Integer,T> - Specified by:
applyin interfacePartialFunction<Integer,T> - Parameters:
index- an index- Returns:
- the element at the given index
- Throws:
IndexOutOfBoundsException- if this is empty, index < 0 or index >= length()
-
asJava
Returns an immutableListview of thisSeq. Any attempt to modify the view (e.g., via mutator methods) will throwUnsupportedOperationExceptionat runtime.This is a view, not a copy. Compared to conversion methods like
toJava*():- Creating the view is O(1) (constant time), whereas conversions take O(n), with n = collection size.
- Operations on the view have the same performance characteristics as the underlying persistent Vavr collection, while converted collections behave like standard Java collections.
Note: the immutable Java list view throws
UnsupportedOperationExceptionbefore checking method arguments, which may differ from standard Java behavior.- Returns:
- an immutable
Listview of this sequence
-
asJava
Creates an immutableListview of thisSeqand passes it to the givenaction.The view is immutable: any attempt to modify it will throw
UnsupportedOperationExceptionat runtime.- Parameters:
action- a side-effecting operation that receives an immutablejava.util.Listview- Returns:
- this sequence
- See Also:
-
asJavaMutable
Returns a mutableListview of thisSeq. All standard mutator methods of theListinterface are supported and modify the underlying view.Unlike
asJava(), this view allows modifications, but the performance characteristics correspond to the underlying persistent Vavr collection.- Returns:
- a mutable
Listview of this sequence - See Also:
-
asJavaMutable
Creates a mutableListview of thisSeqand passes it to the givenaction.The view supports all standard mutator methods. The result of the action determines what is returned:
- If only read operations are performed, this instance is returned.
- If any write operations are performed, a new
Seqreflecting those changes is returned.
- Parameters:
action- a side-effecting operation that receives a mutablejava.util.Listview- Returns:
- this sequence or a new sequence reflecting modifications made through the view
- See Also:
-
asPartialFunction
Returns aPartialFunctionview of thisSeq, where the function is defined at an index if this sequence contains at leastindex + 1elements. Applying the partial function to a defined index returns the element at that index.- Returns:
- a
PartialFunctionmapping indices to elements - Throws:
IndexOutOfBoundsException- if the sequence is empty, or ifindex < 0orindex >= length()
-
collect
Description copied from interface:TraversableApplies aPartialFunctionto all elements that are defined for it and collects the results.For each element in iteration order, the function is first tested:
IfpartialFunction.isDefinedAt(element)true, the element is mapped to typeR:R newElement = partialFunction.apply(element)Note: If this
Traversableis ordered (i.e., extendsOrdered), the caller must ensure that the resulting elements are comparable (i.e., implementComparable).- Specified by:
collectin interfaceTraversable<T>- Type Parameters:
R- the type of elements in the resultingTraversable- Parameters:
partialFunction- a function that may not be defined for all elements of this traversable- Returns:
- a new
Traversablecontaining the results of applying the partial function
-
combinations
Returns a sequence containing all combinations of elements from this sequence, for all sizes from0tolength().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 ]- Returns:
- a sequence of sequences representing all combinations of this sequence's elements
-
combinations
Returns all subsets of this sequence containing exactlykdistinct elements, i.e., the k-combinations of this sequence.- Parameters:
k- the size of each subset- Returns:
- a sequence of sequences representing all k-element combinations
- See Also:
-
containsSlice
Checks whether this sequence contains the given sequence as a contiguous slice.Note: This method may not terminate for infinite sequences.
- Parameters:
that- the sequence to search for; must not benull- Returns:
trueif this sequence contains a slice equal tothat,falseotherwise- Throws:
NullPointerException- ifthatisnull
-
crossProduct
Computes the Cartesian product of this sequence with itself, producing all pairs of elements (this × this).Example:
// Result: [(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)] List.of(1, 2, 3).crossProduct();- Returns:
- an
Iteratorover all pairs in the Cartesian square of this sequence
-
crossProduct
Returns the n-ary Cartesian power (cross product) of this sequence. Each element of the resulting iterator is a sequence of lengthpower, containing all possible combinations of elements from this sequence.Example for power = 2:
// Result: [(A,A), (A,B), (A,C), ..., (B,A), (B,B), ..., (Z,Y), (Z,Z)] CharSeq.rangeClosed('A', 'Z').crossProduct(2);If
poweris negative, the result is an empty iterator:// Result: () CharSeq.rangeClosed('A', 'Z').crossProduct(-1);- Parameters:
power- the number of Cartesian multiplications- Returns:
- an
Iteratorover sequences representing the Cartesian power of this sequence
-
crossProduct
Computes the Cartesian product of this sequence with another iterable, producing pairs of elements (this × that).Example:
// Result: [(1, 'a'), (1, 'b'), (2, 'a'), (2, 'b'), (3, 'a'), (3, 'b')] List.of(1, 2, 3).crossProduct(List.of('a', 'b'));- Type Parameters:
U- the element type of the other iterable- Parameters:
that- another iterable; must not benull- Returns:
- an
Iteratorover all pairs from this sequence andthat - Throws:
NullPointerException- ifthatisnull
-
endsWith
Checks whether this sequence ends with the given sequence.Note: If both this sequence and
thatare infinite, this method may not terminate.- Parameters:
that- the sequence to check as a suffix; must not benull- Returns:
trueif this sequence ends withthat,falseotherwise- Throws:
NullPointerException- ifthatisnull
-
get
Returns the element at the specified index.- Parameters:
index- the position of the element to retrieve- Returns:
- the element at the given index
- Throws:
IndexOutOfBoundsException- if the sequence is empty, or ifindex < 0orindex >= length()
-
indexOf
Returns the index of the first occurrence of the given element, or-1if this sequence does not contain the element.- Parameters:
element- the element to search for- Returns:
- the index of the first occurrence, or
-1if not found
-
indexOfOption
Returns the index of the first occurrence of the given element as anOption.- Parameters:
element- the element to search for- Returns:
Some(index)if the element is found, orNoneif not found
-
indexOf
Returns the index of the first occurrence of the given element, starting at the specified index, or-1if this sequence does not contain the element.- Parameters:
element- the element to search forfrom- the starting index for the search- Returns:
- the index of the first occurrence at or after
from, or-1if not found
-
indexOfOption
Returns the index of the first occurrence of the given element at or after the specified start index, as anOption.- Parameters:
element- the element to search forfrom- the starting index for the search- Returns:
Some(index)if the element is found, orNoneif not found
-
indexOfSlice
Returns the first index at which this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.Note: This method may not terminate for infinite sequences.
- Parameters:
that- the sequence to search for; must not benull- Returns:
- the starting index of the first matching slice, or
-1if not found - Throws:
NullPointerException- ifthatisnull
-
indexOfSliceOption
Returns the first index at which this sequence contains the given sequence as a contiguous slice, wrapped in anOption.Note: This method may not terminate for infinite sequences.
- Parameters:
that- the sequence to search for; must not benull- Returns:
Some(index)if a matching slice is found, orNoneif not found
-
indexOfSlice
Returns the first index at or after the specified start index where this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.Note: This method may not terminate for infinite sequences.
- Parameters:
that- the sequence to search for; must not benullfrom- the starting index for the search- Returns:
- the starting index of the first matching slice at or after
from, or-1if not found - Throws:
NullPointerException- ifthatisnull
-
indexOfSliceOption
Returns the first index at or after the specified start index where this sequence contains the given sequence as a contiguous slice, wrapped in anOption.Note: This method may not terminate for infinite sequences.
- Parameters:
that- the sequence to search for; must not benullfrom- the starting index for the search- Returns:
Some(index)if a matching slice is found, orNoneif not found
-
indexWhere
Returns the index of the first element in this sequence that satisfies the given predicate, or-1if no such element exists.- Parameters:
predicate- the predicate used to test elements; must not benull- Returns:
- the index of the first matching element, or
-1if none exists
-
indexWhereOption
Returns the index of the first element satisfying the given predicate as anOption.- Parameters:
predicate- the predicate used to test elements; must not benull- Returns:
Some(index)if a matching element exists, orNoneif not found
-
indexWhere
Returns the index of the first element at or after the specified start index that satisfies the given predicate, or-1if no such element exists.- Parameters:
predicate- the predicate used to test elements; must not benullfrom- the starting index for the search- Returns:
- the index
>= fromof the first matching element, or-1if none exists
-
indexWhereOption
Returns the index of the first element at or after the specified start index that satisfies the given predicate as anOption.- Parameters:
predicate- the predicate used to test elements; must not benullfrom- the starting index for the search- Returns:
Some(index)if a matching element exists, orNoneif not found
-
insert
Returns a new sequence with the given element inserted at the specified index.- Parameters:
index- the position at which to insert the elementelement- the element to insert- Returns:
- a new
Seqwith the element inserted - Throws:
IndexOutOfBoundsException- if the sequence is empty, or ifindex < 0orindex >= length()
-
insertAll
Returns a new sequence with the given elements inserted at the specified index.- Parameters:
index- the position at which to insert the elementselements- the elements to insert; must not benull- Returns:
- a new
Seqwith the elements inserted - Throws:
IndexOutOfBoundsException- if the sequence is empty, or ifindex < 0orindex >= length()
-
intersperse
Returns a new sequence where the given element is inserted between all elements of this sequence.- Parameters:
element- the element to intersperse- Returns:
- a new
Seqwith the element interspersed
-
iterator
Returns an iterator over the elements of this sequence starting at the specified index. Equivalent tothis.subSequence(index).iterator().- Parameters:
index- the starting index- Returns:
- an
Iteratorbeginning at the given index, or empty ifindex == length() - Throws:
IndexOutOfBoundsException- ifindex < 0orindex > length()
-
lastIndexOf
Returns the index of the last occurrence of the given element, or-1if this sequence does not contain the element.- Parameters:
element- the element to search for- Returns:
- the index of the last occurrence, or
-1if not found
-
lastIndexOfOption
Returns the index of the last occurrence of the given element as anOption.- Parameters:
element- the element to search for- Returns:
Some(index)if found, orNoneif not found
-
lastIndexWhere
Returns the index of the last element in this sequence that satisfies the given predicate, or-1if no such element exists.- Parameters:
predicate- the predicate used to test elements; must not benull- Returns:
- the index of the last matching element, or
-1if none exists
-
lastIndexWhereOption
Returns the index of the last element satisfying the given predicate as anOption.- Parameters:
predicate- the predicate used to test elements; must not benull- Returns:
Some(index)if a matching element exists, orNoneif not found
-
lastIndexWhere
Returns the index of the last element at or before the specified end index that satisfies the given predicate, or-1if no such element exists.- Parameters:
predicate- the predicate used to test elements; must not benullend- the maximum index to consider- Returns:
- the index
<= endof the last matching element, or-1if none exists
-
lastIndexWhereOption
Returns the index of the last element at or before the specified end index that satisfies the given predicate, wrapped in anOption.- Parameters:
predicate- the predicate used to test elements; must not benullend- the maximum index to consider- Returns:
Some(index)if a matching element exists, orNoneif not found
-
lift
Deprecated.Will be removedTurns this sequence into a plain function returning an Option result.- Specified by:
liftin interfacePartialFunction<Integer,T> - Returns:
- a function that takes an index i and returns the value of this sequence in a Some if the index is within bounds, otherwise a None.
-
lastIndexOf
Returns the index of the last occurrence of the given element at or before the specified end index, or-1if this sequence does not contain the element.- Parameters:
element- the element to search forend- the maximum index to consider- Returns:
- the index of the last occurrence at or before
end, or-1if not found
-
lastIndexOfOption
Returns the index of the last occurrence of the given element at or before the specified end index as anOption.- Parameters:
element- the element to search forend- the maximum index to consider- Returns:
Some(index)if found, orNoneif not found
-
lastIndexOfSlice
Returns the last index where this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.Note: This method will not terminate for infinite sequences.
- Parameters:
that- the sequence to search for; must not benull- Returns:
- the starting index of the last matching slice, or
-1if not found - Throws:
NullPointerException- ifthatisnull
-
lastIndexOfSliceOption
Returns the last index where this sequence contains the given sequence as a contiguous slice, wrapped in anOption.- Parameters:
that- the sequence to search for; must not benull- Returns:
Some(index)if a matching slice exists, orNoneif not found
-
lastIndexOfSlice
Returns the last index at or before the specified end index where this sequence contains the given sequence as a contiguous slice, or-1if no such slice exists.- Parameters:
that- the sequence to search for; must not benullend- the maximum index to consider- Returns:
- the last index
<= endwhere the slice starts, or-1if not found - Throws:
NullPointerException- ifthatisnull
-
lastIndexOfSliceOption
Returns the last index at or before the specified end index where this sequence contains the given sequence as a contiguous slice, wrapped in anOption.- Parameters:
that- the sequence to search for; must not benullend- the maximum index to consider- Returns:
Some(index)if a matching slice exists, orNoneif not found
-
padTo
Returns a new sequence with this sequence padded on the right with the given element until the specified target length is reached.Note: Lazily-evaluated sequences may need to process all elements to determine the overall length.
- Parameters:
length- the target length of the resulting sequenceelement- the element to append as padding- Returns:
- a new
Seqconsisting of this sequence followed by the minimal number of occurrences ofelementto reach at leastlength
-
leftPadTo
Returns a new sequence with this sequence padded on the left with the given element until the specified target length is reached.Note: Lazily-evaluated sequences may need to process all elements to determine the overall length.
- Parameters:
length- the target length of the resulting sequenceelement- the element to prepend as padding- Returns:
- a new
Seqconsisting of this sequence prepended by the minimal number of occurrences ofelementto reach at leastlength
-
patch
Returns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.- Parameters:
from- the starting index of the slice to be replacedthat- the sequence of elements to insert; must not benullreplaced- the number of elements to remove from this sequence starting atfrom- Returns:
- a new
Seqwith the specified slice replaced
-
permutations
Returns all unique permutations of this sequence.Example:
[].permutations() = [] [1, 2, 3].permutations() = [ [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1] ]- Returns:
- a sequence of all unique permutations of this sequence
-
prefixLength
Returns the length of the longest prefix of this sequence whose elements all satisfy the given predicate.Note: This method may not terminate for infinite sequences.
- Parameters:
predicate- the predicate to test elements; must not benull- Returns:
- the length of the longest prefix in which every element satisfies
predicate
-
prepend
Returns a new sequence with the given element prepended to this sequence.- Parameters:
element- the element to prepend- Returns:
- a new
Seqwith the element added at the front
-
prependAll
Returns a new sequence with all given elements prepended to this sequence.- Parameters:
elements- the elements to prepend; must not benull- Returns:
- a new
Seqwith the elements added at the front
-
remove
Returns a new sequence with the first occurrence of the given element removed.- Parameters:
element- the element to remove- Returns:
- a new
Seqwithout the first occurrence of the element
-
removeAll
Returns a new sequence with all occurrences of the given element removed.- Parameters:
element- the element to remove- Returns:
- a new
Seqwithout any occurrences of the element
-
removeAll
Returns a new sequence with all occurrences of the given elements removed.- Parameters:
elements- the elements to remove; must not benull- Returns:
- a new
Seqwithout any of the given elements - Throws:
NullPointerException- ifelementsisnull
-
removeAll
Deprecated.Please usereject(Predicate)Returns a new Seq consisting of all elements which do not satisfy the given predicate.- Parameters:
predicate- the predicate used to test elements- Returns:
- a new Seq
- Throws:
NullPointerException- ifpredicateis null
-
removeAt
Returns a new sequence with the element at the specified position removed. Subsequent elements are shifted to the left (indices decreased by one).- Parameters:
index- the position of the element to remove- Returns:
- a new
Seqwithout the element at the specified index - Throws:
IndexOutOfBoundsException- if the sequence is empty, or ifindex < 0orindex >= length()
-
removeFirst
Returns a new sequence with the first element that satisfies the given predicate removed.- Parameters:
predicate- the predicate used to identify the element to remove; must not benull- Returns:
- a new
Seqwithout the first matching element
-
removeLast
Returns a new sequence with the last element that satisfies the given predicate removed.- Parameters:
predicate- the predicate used to identify the element to remove; must not benull- Returns:
- a new
Seqwithout the last matching element
-
reverse
Returns a new sequence with the order of elements reversed.- Returns:
- a new
Seqwith elements in reversed order
-
reverseIterator
Returns an iterator that yields elements of this sequence in reversed order.Note:
xs.reverseIterator()is equivalent toxs.reverse().iterator()but may be more efficient.- Returns:
- an
Iteratorover the elements in reversed order
-
rotateLeft
Returns a new sequence with the elements circularly rotated to the left by the specified distance.Example:
// Result: List(3, 4, 5, 1, 2) List.of(1, 2, 3, 4, 5).rotateLeft(2);- Parameters:
n- the number of positions to rotate left- Returns:
- a new
Seqwith elements rotated left
-
rotateRight
Returns a new sequence with the elements circularly rotated to the right by the specified distance.Example:
// Result: List(4, 5, 1, 2, 3) List.of(1, 2, 3, 4, 5).rotateRight(2);- Parameters:
n- the number of positions to rotate right- Returns:
- a new
Seqwith elements rotated right
-
segmentLength
Returns the length of the longest contiguous segment, starting from the specified index, in which all elements satisfy the given predicate.Note: This method may not terminate for infinite sequences.
- Parameters:
predicate- the predicate used to test elements; must not benullfrom- the index at which to start the search- Returns:
- the length of the longest segment starting at
fromwhere every element satisfiespredicate
-
shuffle
Returns a new sequence with the elements randomly shuffled.- Returns:
- a new
Seqcontaining the same elements in a random order
-
slice
Returns a subsequence (slice) of this sequence, starting atbeginIndex(inclusive) and ending atendIndex(exclusive).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 may throw an exception instead of returning a sequence in some cases.- Parameters:
beginIndex- the starting index (inclusive)endIndex- the ending index (exclusive)- Returns:
- a new
Seqrepresenting the specified slice
-
sorted
Returns a new sequence with elements sorted according to their natural order.- Returns:
- a new
Seqwith elements in natural order - Throws:
ClassCastException- if elements are notComparable
-
sorted
Returns a new sequence with elements sorted according to the givenComparator.- Parameters:
comparator- the comparator used to order elements; must not benull- Returns:
- a new
Seqwith elements sorted according to the comparator
-
sortBy
Returns a new sequence sorted by comparing elements in a different domain defined by the givenmapper.- Type Parameters:
U- the type used for comparison- Parameters:
mapper- a function mapping elements to aComparabledomain; must not benull- Returns:
- a new
Seqsorted according to the mapped values - Throws:
NullPointerException- ifmapperisnull
-
sortBy
<U> Seq<T> sortBy(@NonNull Comparator<? super U> comparator, Function<? super T, ? extends U> mapper) Returns a new sequence sorted by comparing elements in a different domain defined by the givenmapper, using the providedcomparator.- Type Parameters:
U- the type used for comparison- Parameters:
comparator- the comparator used to compare mapped values; must not benullmapper- a function mapping elements to the domain for comparison; must not benull- Returns:
- a new
Seqsorted according to the mapped values and comparator - Throws:
NullPointerException- ifcomparatorormapperisnull
-
splitAt
Splits this sequence at the specified index.The result of
splitAt(n)is equivalent toTuple.of(take(n), drop(n)).- Parameters:
n- the index at which to split- Returns:
- a
Tuple2containing the firstnelements and the remaining elements
-
splitAt
Splits this sequence at the first element satisfying the given predicate.- Parameters:
predicate- the predicate used to determine the split point; must not benull- Returns:
- a
Tuple2containing the sequence before the first matching element and the remaining sequence
-
splitAtInclusive
Splits this sequence at the first element satisfying the given predicate, including the element in the first part.- Parameters:
predicate- the predicate used to determine the split point; must not benull- Returns:
- a
Tuple2containing the sequence up to and including the first matching element and the remaining sequence
-
startsWith
Tests whether this sequence starts with the given sequence.- Parameters:
that- the sequence to test; must not benull- Returns:
trueifthatis empty or is a prefix of this sequence,falseotherwise
-
startsWith
Tests whether this sequence contains the given sequence starting at the specified index.Note: If both this sequence and the argument sequence are infinite, this method may not terminate.
- Parameters:
that- the sequence to test; must not benulloffset- the index at which to start checking for the prefix- Returns:
trueifthatis empty or matches a subsequence of this sequence starting atoffset,falseotherwise
-
subSequence
Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndexand extending to the end of this sequence.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 IndexOutOfBoundsExceptionSee also
drop(int), which provides similar functionality but does not throw an exception for out-of-bounds indices.- Parameters:
beginIndex- the starting index (inclusive) of the subsequence- Returns:
- a new
Seqrepresenting the subsequence frombeginIndexto the end - Throws:
IndexOutOfBoundsException- ifbeginIndexis negative or greater than the length of this sequence
-
subSequence
Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndex(inclusive) and ending atendIndex(exclusive).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 IndexOutOfBoundsExceptionSee also
slice(int, int), which returns an empty sequence instead of throwing exceptions when indices are out of range.- Parameters:
beginIndex- the starting index (inclusive) of the subsequenceendIndex- the ending index (exclusive) of the subsequence- Returns:
- a new
Seqrepresenting the subsequence frombeginIndextoendIndex - 1 - Throws:
IndexOutOfBoundsException- ifbeginIndexorendIndexis negative, or ifendIndexis greater thanlength()IllegalArgumentException- ifbeginIndexis greater thanendIndex
-
update
Returns a newSeqwith the element at the specified index replaced by the given value.- Parameters:
index- the index of the element to updateelement- the new element to set at the specified index- Returns:
- a new
Seqwith the updated element - Throws:
IndexOutOfBoundsException- ifindexis negative or greater than or equal tolength()
-
update
Returns a newSeqwith the element at the specified index updated using the given function.- Parameters:
index- the index of the element to updateupdater- a function that computes the new element from the existing element- Returns:
- a new
Seqwith the element atindextransformed byupdater - Throws:
IndexOutOfBoundsException- ifindexis negative or greater than or equal tolength()NullPointerException- ifupdateris null
-
search
Searches for a specified element in this sequence, which must be sorted in ascending natural order.If the sequence is an
IndexedSeq, a binary search is used; otherwise, a linear search is performed.- Parameters:
element- the element to search for- Returns:
- the index of the element if found; otherwise,
-(insertion point) - 1, where the insertion point is the index at which the element would be inserted. A non-negative return value indicates the element is present. - Throws:
ClassCastException- if the element cannot be compared using natural ordering
-
search
Searches for a specified element in this sequence, which must be sorted according to the given comparator.If the sequence is an
IndexedSeq, a binary search is used; otherwise, a linear search is performed.- Parameters:
element- the element to search forcomparator- the comparator defining the order of the sequence- Returns:
- the index of the element if found; otherwise,
-(insertion point) - 1, where the insertion point is the index at which the element would be inserted. A non-negative return value indicates the element is present. - Throws:
NullPointerException- ifcomparatoris null
-
distinct
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance with all duplicates removed. Element equality is determined usingequals.- Specified by:
distinctin interfaceTraversable<T>- Returns:
- a new
Traversablewithout duplicate elements
-
distinctBy
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.- Specified by:
distinctByin interfaceTraversable<T>- Parameters:
comparator- a comparator used to determine equality of elements- Returns:
- a new
Traversablewith duplicates removed
-
distinctBy
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.The first occurrence of each key is retained in the resulting sequence.
- Specified by:
distinctByin interfaceTraversable<T>- Type Parameters:
U- the type of key- Parameters:
keyExtractor- a function to extract keys for determining uniqueness- Returns:
- a new
Traversablewith duplicates removed based on keys
-
distinctByKeepLast
Returns a sequence with duplicate elements removed, as determined by the provided comparator. When duplicates are found, the **last occurrence** of each element is retained.- Parameters:
comparator- a comparator defining equality between elements- Returns:
- a new sequence with duplicates removed, keeping the last occurrence of each element
-
distinctByKeepLast
Returns a sequence with duplicates removed based on a key extracted from each element. The key is obtained via the providedkeyExtractorfunction. When duplicates are found, the **last occurrence** of each element for a given key is retained.- Type Parameters:
U- the type of the key used for determining uniqueness- Parameters:
keyExtractor- a function extracting a key from each element for uniqueness comparison- Returns:
- a new sequence of elements distinct by the extracted key, keeping the last occurrence
-
drop
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropin interfaceTraversable<T>- Parameters:
n- the number of elements to drop- Returns:
- a new instance excluding the first
nelements
-
dropUntil
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.- Specified by:
dropUntilin interfaceTraversable<T>- Parameters:
predicate- a condition tested on each element- Returns:
- a new instance starting from the first element matching the predicate
-
dropWhile
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.This is equivalent to
dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.- Specified by:
dropWhilein interfaceTraversable<T>- Parameters:
predicate- a condition tested on each element- Returns:
- a new instance starting from the first element not matching the predicate
-
dropRight
Description copied from interface:TraversableReturns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropRightin interfaceTraversable<T>- Parameters:
n- the number of elements to drop from the end- Returns:
- a new instance excluding the last
nelements
-
dropRightUntil
Drops elements from the end of the sequence until an element satisfies the given predicate. The returned sequence includes the last element that satisfies the predicate.- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements up to and including the last element that satisfies the predicate
- Throws:
NullPointerException- ifpredicateis null
-
dropRightWhile
Drops elements from the end of the sequence while the given predicate holds.This is equivalent to
dropRightUntil(predicate.negate()). Useful when using method references that cannot be negated directly.- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements up to and including the last element that does not satisfy the predicate
- Throws:
NullPointerException- ifpredicateis null
-
filter
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.- Specified by:
filterin interfaceTraversable<T>- Parameters:
predicate- the condition to test elements- Returns:
- a traversable with elements matching the predicate
-
reject
Description copied from interface:TraversableReturns a new traversable containing only the elements that do not satisfy the given predicate.This is equivalent to
filter(predicate.negate()).- Specified by:
rejectin interfaceTraversable<T>- Parameters:
predicate- the condition to test elements- Returns:
- a traversable with elements not matching the predicate
-
flatMap
Description copied from interface:TraversableTransforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.- Specified by:
flatMapin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the resulting Traversable- Parameters:
mapper- a function mapping elements to iterables- Returns:
- a new Traversable containing all elements produced by applying
mapperand flattening
-
foldRight
Description copied from interface:FoldableFolds the elements of this structure from the right, starting with the givenzerovalue and successively applying thecombinefunction to each element.Folding from the right means that elements are combined starting from the last element and associating each step with the accumulated result so far.
Example:
// Result: "!cba" List.of("a", "b", "c").foldRight("!", (x, acc) -> acc + x);- Specified by:
foldRightin interfaceFoldable<T>- Specified by:
foldRightin interfaceTraversable<T>- Type Parameters:
U- the type of the accumulated result- Parameters:
zero- the initial value to start folding withf- a function that combines the next element and the accumulated value- Returns:
- the folded result
-
groupBy
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceTraversable<T>- Type Parameters:
C- The type of the group keys- Parameters:
classifier- A function that assigns each element to a group- Returns:
- A map where each key corresponds to a group of elements
- See Also:
-
grouped
Description copied from interface:TraversableSplits thisTraversableinto consecutive blocks of the given size.Let
lengthbe the number of elements in thisTraversable:- If empty, the resulting
Iteratoris empty. - If
size <= length, the resultingIteratorcontainslength / sizeblocks of sizesizeand possibly a final smaller block of sizelength % size. - If
size > length, the resultingIteratorcontains a single block of sizelength.
Examples:
[].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]]Note:
grouped(size)is equivalent tosliding(size, size).- Specified by:
groupedin interfaceTraversable<T>- Parameters:
size- the block size; must be positive- Returns:
- an
Iteratorover blocks of elements
- If empty, the resulting
-
init
Description copied from interface:TraversableReturns all elements of this Traversable except the last one.This is the dual of
Traversable.tail().- Specified by:
initin interfaceTraversable<T>- Returns:
- a new instance containing all elements except the last
-
initOption
Description copied from interface:TraversableReturns all elements of this Traversable except the last one, wrapped in anOption.This is the dual of
Traversable.tailOption().- Specified by:
initOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, orNoneif this Traversable is empty
-
map
Description copied from interface:TraversableTransforms the elements of this Traversable to a new type, preserving order if defined. -
mapTo
Description copied from interface:ValueMaps the underlying value to another fixed value. -
mapToVoid
Description copied from interface:ValueMaps the underlying value to Void -
orElse
Description copied from interface:TraversableReturns thisTraversableif it is non-empty; otherwise, returns the given alternative.- Specified by:
orElsein interfaceTraversable<T>- Parameters:
other- an alternativeTraversableto return if this is empty- Returns:
- this
Traversableif non-empty, otherwiseother
-
orElse
Description copied from interface:TraversableReturns thisTraversableif it is non-empty; otherwise, returns the result of evaluating the given supplier.- Specified by:
orElsein interfaceTraversable<T>- Parameters:
supplier- a supplier of an alternativeTraversableif this is empty- Returns:
- this
Traversableif non-empty, otherwise the result ofsupplier.get()
-
partition
Description copied from interface:TraversableSplits thisTraversableinto two partitions according to a predicate.The first partition contains all elements that satisfy the predicate, and the second contains all elements that do not. The original iteration order is preserved.
- Specified by:
partitionin interfaceTraversable<T>- Parameters:
predicate- a predicate used to classify elements- Returns:
- a
Tuple2containing the two resultingTraversableinstances
-
peek
Description copied from interface:ValuePerforms the givenactionon the first element if this is an eager implementation. Performs the givenactionon all elements (the first immediately, successive deferred), if this is a lazy implementation. -
replace
Description copied from interface:TraversableReplaces the first occurrence ofcurrentElementwithnewElement, if it exists.- Specified by:
replacein interfaceTraversable<T>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with the first occurrence of
currentElementreplaced bynewElement
-
replaceAll
Description copied from interface:TraversableReplaces all occurrences ofcurrentElementwithnewElement.- Specified by:
replaceAllin interfaceTraversable<T>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with all occurrences of
currentElementreplaced bynewElement
-
retainAll
Description copied from interface:TraversableRetains only the elements from this Traversable that are contained in the givenelements.- Specified by:
retainAllin interfaceTraversable<T>- Parameters:
elements- the elements to keep- Returns:
- a new Traversable containing only the elements present in
elements, in their original order
-
scan
Description copied from interface:TraversableComputes a prefix scan of the elements of this Traversable.The neutral element
zeromay be applied more than once.- Specified by:
scanin interfaceTraversable<T>- Parameters:
zero- the neutral element for the operatoroperation- an associative binary operator- Returns:
- a new Traversable containing the prefix scan of the elements
-
scanLeft
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from left to right.Will not terminate for infinite collections. The results may vary across runs unless the collection is ordered.
- Specified by:
scanLeftin interfaceTraversable<T>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to the intermediate result and each element- Returns:
- a new Traversable containing the cumulative results
-
scanRight
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from right to left.The head of the resulting collection is the last cumulative result. Will not terminate for infinite collections. Results may vary across runs unless the collection is ordered.
- Specified by:
scanRightin interfaceTraversable<T>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to each element and the intermediate result- Returns:
- a new Traversable containing the cumulative results
-
slideBy
Description copied from interface:TraversablePartitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Each window contains elements with the same class, as determined by
classifier. Two consecutive elements belong to the same window only ifclassifierreturns equal values for both. Otherwise, the current window ends and a new window begins with the next element.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]]- Specified by:
slideByin interfaceTraversable<T>- Parameters:
classifier- A function classifying elements into groups- Returns:
- An
Iteratorof windows (grouped elements)
-
sliding
Description copied from interface:TraversableSlides a window of a givensizeover thisTraversablewith a step size of 1.This is equivalent to calling
Traversable.sliding(int, int)with a step size of 1.- Specified by:
slidingin interfaceTraversable<T>- Parameters:
size- a positive window size- Returns:
- An
Iteratorof windows, each containing up tosizeelements
-
sliding
Description copied from interface:TraversableSlides a window of a specificsizewith a givenstepover thisTraversable.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]]- Specified by:
slidingin interfaceTraversable<T>- Parameters:
size- a positive window sizestep- a positive step size- Returns:
- an
Iteratorof windows with the given size and step
-
span
Description copied from interface:TraversableSplits thisTraversableinto a prefix and remainder according to the givenpredicate.The first element of the returned
Tupleis the longest prefix of elements satisfyingpredicate, and the second element is the remaining elements.- Specified by:
spanin interfaceTraversable<T>- Parameters:
predicate- a predicate used to determine the prefix- Returns:
- a
Tuplecontaining the prefix and remainder
-
tail
Description copied from interface:TraversableReturns a newTraversablewithout its first element.- Specified by:
tailin interfaceTraversable<T>- Returns:
- a new
Traversablecontaining all elements except the first
-
tailOption
Description copied from interface:TraversableReturns a newTraversablewithout its first element as anOption.- Specified by:
tailOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, otherwiseNone
-
take
Description copied from interface:TraversableReturns the firstnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(0, max(0, min(length(), n))), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.- Specified by:
takein interfaceTraversable<T>- Parameters:
n- the number of elements to take- Returns:
- a new
Traversablecontaining the firstnelements
-
takeUntil
Description copied from interface:TraversableTakes elements from thisTraversableuntil the given predicate holds for an element.Equivalent to
takeWhile(predicate.negate()), but useful when using method references that cannot be negated directly.- Specified by:
takeUntilin interfaceTraversable<T>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements before the first one that satisfies the predicate
-
takeWhile
Description copied from interface:TraversableTakes elements from thisTraversablewhile the given predicate holds.- Specified by:
takeWhilein interfaceTraversable<T>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements up to (but not including) the first one that does not satisfy the predicate
-
takeRight
Description copied from interface:TraversableReturns the lastnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(max(0, length() - n), length()), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.- Specified by:
takeRightin interfaceTraversable<T>- Parameters:
n- the number of elements to take from the end- Returns:
- a new
Traversablecontaining the lastnelements
-
takeRightUntil
Takes elements from the end of the sequence until an element satisfies the given predicate. The returned sequence starts after the last element that satisfies the predicate.- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements after the last element that satisfies the predicate
- Throws:
NullPointerException- ifpredicateis null
-
takeRightWhile
Takes elements from the end of the sequence while the given predicate holds.This is an equivalent to
takeRightUntil(predicate.negate()). Useful when using method references that cannot be negated directly.- Parameters:
predicate- a condition to test elements, starting from the end- Returns:
- a new sequence containing all elements after the last element that does not satisfy the predicate
- Throws:
NullPointerException- ifpredicateis null
-
unzip
<T1,T2> Tuple2<? extends Seq<T1>,? extends Seq<T2>> unzip(@NonNull Function<? super T, Tuple2<? extends T1, ? extends T2>> unzipper) Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.- Specified by:
unzipin interfaceTraversable<T>- Type Parameters:
T1- type of the first element in the resulting pairsT2- type of the second element in the resulting pairs- Parameters:
unzipper- a function that maps elements of thisTraversableto pairs- Returns:
- a
Tuple2containing twoTraversablecollections with the split elements
-
unzip3
<T1,T2, Tuple3<? extends Seq<T1>,T3> ? extends Seq<T2>, unzip3? extends Seq<T3>> (@NonNull Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.- Specified by:
unzip3in interfaceTraversable<T>- Type Parameters:
T1- type of the first element in the resulting triplesT2- type of the second element in the resulting triplesT3- type of the third element in the resulting triples- Parameters:
unzipper- a function that maps elements of thisTraversableto triples- Returns:
- a
Tuple3containing threeTraversablecollections with the split elements
-
zip
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable. Pairing stops when either collection runs out of elements; any remaining elements in the longer collection are ignored.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pair- Returns:
- a new
Traversablecontaining pairs of corresponding elements
-
zipWith
<U,R> Seq<R> zipWith(@NonNull Iterable<? extends U> that, BiFunction<? super T, ? super U, ? extends R> mapper) Description copied from interface:TraversableReturns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function. Pairing stops when either collection runs out of elements.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipWithin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second parameter of the mapperR- the type of elements in the resultingTraversable- Parameters:
that- anIterableproviding the second parameter of the mappermapper- a function that combines elements from this andthatinto a new element- Returns:
- a new
Traversablecontaining mapped elements
-
zipAll
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.The length of the resulting
Traversableis the maximum of the lengths of thisTraversableandthat.If this
Traversableis shorter thanthat,thisElemis used as a filler. Conversely, ifthatis shorter,thatElemis used.- Specified by:
zipAllin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pairthisElem- the element used to fill missing values if thisTraversableis shorter thanthatthatElem- the element used to fill missing values ifthatis shorter than thisTraversable- Returns:
- a new
Traversablecontaining pairs of elements, including fillers as needed
-
zipWithIndex
Description copied from interface:TraversableZips thisTraversablewith its indices, starting at 0.- Specified by:
zipWithIndexin interfaceTraversable<T>- Returns:
- a new
Traversablecontaining each element paired with its index
-
zipWithIndex
Description copied from interface:TraversableZips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.- Specified by:
zipWithIndexin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the resultingTraversable- Parameters:
mapper- a function mapping an element and its index to a new element- Returns:
- a new
Traversablecontaining the mapped elements
-
withDefaultValue
Deprecated.Will be removedTurns this sequence from a partial function into a total function that returns defaultValue for all indexes that are out of bounds.- Parameters:
defaultValue- default value to return for out of bound indexes- Returns:
- a total function from index to T
-
withDefault
@Deprecated default Function1<Integer,T> withDefault(@NonNull Function<? super Integer, ? extends T> defaultFunction) Deprecated.Will be removedTurns 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.- Parameters:
defaultFunction- function to evaluate for all out-of-bounds indexes.- Returns:
- a total function from index to T
-
isSequential
default boolean isSequential()Description copied from interface:TraversableIndicates whether the elements of this Traversable appear in encounter (insertion) order.- Specified by:
isSequentialin interfaceTraversable<T>- Returns:
trueif insertion order is preserved,falseotherwise
-