Interface LinearSeq<T>
-
- Type Parameters:
T- component type
- All Superinterfaces:
Foldable<T>,java.util.function.Function<java.lang.Integer,T>,Function1<java.lang.Integer,T>,java.lang.Iterable<T>,PartialFunction<java.lang.Integer,T>,Seq<T>,java.io.Serializable,Traversable<T>,Value<T>
- All Known Implementing Classes:
List.Cons,List.Nil,Queue,Stream.Cons,Stream.Empty,StreamModule.AppendElements,StreamModule.ConsImpl
public interface LinearSeq<T> extends Seq<T>
Interface for immutable, linear sequences.Efficient
head(),tail(), andisEmpty()methods are characteristic for linear sequences.
-
-
Field Summary
Fields Modifier and Type Field Description static longserialVersionUIDThe serial version UID for serialization.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description LinearSeq<T>append(T element)Returns a new sequence with the given element appended at the end.LinearSeq<T>appendAll(@NonNull java.lang.Iterable<? extends T> elements)Returns a new sequence with all elements from the givenIterableappended at the end of this sequence.LinearSeq<T>asJava(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)Creates an immutableListview of thisSeqand passes it to the givenaction.LinearSeq<T>asJavaMutable(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)Creates a mutableListview of thisSeqand passes it to the givenaction.default PartialFunction<java.lang.Integer,T>asPartialFunction()Returns aPartialFunctionview of thisSeq, where the function is defined at an index if this sequence contains at leastindex + 1elements.<R> LinearSeq<R>collect(@NonNull PartialFunction<? super T,? extends R> partialFunction)Applies aPartialFunctionto all elements that are defined for it and collects the results.LinearSeq<? extends LinearSeq<T>>combinations()Returns a sequence containing all combinations of elements from this sequence, for all sizes from0tolength().LinearSeq<? extends LinearSeq<T>>combinations(int k)Returns all subsets of this sequence containing exactlykdistinct elements, i.e., the k-combinations of this sequence.Iterator<? extends LinearSeq<T>>crossProduct(int power)Returns the n-ary Cartesian power (cross product) of this sequence.LinearSeq<T>distinct()Returns a newTraversablecontaining the elements of this instance with all duplicates removed.LinearSeq<T>distinctBy(@NonNull java.util.Comparator<? super T> comparator)Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.<U> LinearSeq<T>distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.LinearSeq<T>distinctByKeepLast(@NonNull java.util.Comparator<? super T> comparator)Returns a sequence with duplicate elements removed, as determined by the provided comparator.<U> LinearSeq<T>distinctByKeepLast(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)Returns a sequence with duplicates removed based on a key extracted from each element.LinearSeq<T>drop(int n)Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.LinearSeq<T>dropRight(int n)Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.LinearSeq<T>dropRightUntil(@NonNull java.util.function.Predicate<? super T> predicate)Drops elements from the end of the sequence until an element satisfies the given predicate.LinearSeq<T>dropRightWhile(@NonNull java.util.function.Predicate<? super T> predicate)Drops elements from the end of the sequence while the given predicate holds.LinearSeq<T>dropUntil(@NonNull java.util.function.Predicate<? super T> predicate)Returns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.LinearSeq<T>dropWhile(@NonNull java.util.function.Predicate<? super T> predicate)Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.LinearSeq<T>filter(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that satisfy the given predicate.<U> LinearSeq<U>flatMap(@NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)Transforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.<C> Map<C,? extends LinearSeq<T>>groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)Groups elements of thisTraversablebased on a classifier function.Iterator<? extends LinearSeq<T>>grouped(int size)Splits thisTraversableinto consecutive blocks of the given size.default intindexOfSlice(@NonNull java.lang.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.default intindexWhere(@NonNull java.util.function.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.LinearSeq<T>init()Returns all elements of this Traversable except the last one.Option<? extends LinearSeq<T>>initOption()Returns all elements of this Traversable except the last one, wrapped in anOption.LinearSeq<T>insert(int index, T element)Returns a new sequence with the given element inserted at the specified index.LinearSeq<T>insertAll(int index, @NonNull java.lang.Iterable<? extends T> elements)Returns a new sequence with the given elements inserted at the specified index.LinearSeq<T>intersperse(T element)Returns a new sequence where the given element is inserted between all elements of this sequence.default booleanisDefinedAt(java.lang.Integer index)Deprecated.default intlastIndexOfSlice(@NonNull java.lang.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.default intlastIndexWhere(@NonNull java.util.function.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.<U> LinearSeq<U>map(@NonNull java.util.function.Function<? super T,? extends U> mapper)Transforms the elements of this Traversable to a new type, preserving order if defined.default <U> LinearSeq<U>mapTo(U value)Maps the underlying value to another fixed value.default LinearSeq<java.lang.Void>mapToVoid()Maps the underlying value to Voidstatic <T> LinearSeq<T>narrow(LinearSeq<? extends T> linearSeq)Narrows a widenedLinearSeq<? extends T>toLinearSeq<T>by performing a type-safe cast.LinearSeq<T>orElse(@NonNull java.lang.Iterable<? extends T> other)Returns thisTraversableif it is non-empty; otherwise, returns the given alternative.LinearSeq<T>orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)Returns thisTraversableif it is non-empty; otherwise, returns the result of evaluating the given supplier.LinearSeq<T>padTo(int length, T element)Returns a new sequence with this sequence padded on the right with the given element until the specified target length is reached.Tuple2<? extends LinearSeq<T>,? extends LinearSeq<T>>partition(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto two partitions according to a predicate.LinearSeq<T>patch(int from, @NonNull java.lang.Iterable<? extends T> that, int replaced)Returns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.LinearSeq<T>peek(@NonNull java.util.function.Consumer<? super T> action)Performs the givenactionon the first element if this is an eager implementation.LinearSeq<? extends LinearSeq<T>>permutations()Returns all unique permutations of this sequence.LinearSeq<T>prepend(T element)Returns a new sequence with the given element prepended to this sequence.LinearSeq<T>prependAll(@NonNull java.lang.Iterable<? extends T> elements)Returns a new sequence with all given elements prepended to this sequence.LinearSeq<T>reject(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that do not satisfy the given predicate.LinearSeq<T>remove(T element)Returns a new sequence with the first occurrence of the given element removed.LinearSeq<T>removeAll(@NonNull java.lang.Iterable<? extends T> elements)Returns a new sequence with all occurrences of the given elements removed.LinearSeq<T>removeAll(@NonNull java.util.function.Predicate<? super T> predicate)Deprecated.LinearSeq<T>removeAll(T element)Returns a new sequence with all occurrences of the given element removed.LinearSeq<T>removeAt(int index)Returns a new sequence with the element at the specified position removed.LinearSeq<T>removeFirst(@NonNull java.util.function.Predicate<T> predicate)Returns a new sequence with the first element that satisfies the given predicate removed.LinearSeq<T>removeLast(@NonNull java.util.function.Predicate<T> predicate)Returns a new sequence with the last element that satisfies the given predicate removed.LinearSeq<T>replace(T currentElement, T newElement)Replaces the first occurrence ofcurrentElementwithnewElement, if it exists.LinearSeq<T>replaceAll(T currentElement, T newElement)Replaces all occurrences ofcurrentElementwithnewElement.LinearSeq<T>retainAll(@NonNull java.lang.Iterable<? extends T> elements)Retains only the elements from this Traversable that are contained in the givenelements.LinearSeq<T>reverse()Returns a new sequence with the order of elements reversed.default Iterator<T>reverseIterator()Returns an iterator that yields elements of this sequence in reversed order.LinearSeq<T>rotateLeft(int n)Returns a new sequence with the elements circularly rotated to the left by the specified distance.LinearSeq<T>rotateRight(int n)Returns a new sequence with the elements circularly rotated to the right by the specified distance.LinearSeq<T>scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)Computes a prefix scan of the elements of this Traversable.<U> LinearSeq<U>scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super T,? extends U> operation)Produces a collection containing cumulative results of applying the operator from left to right.<U> LinearSeq<U>scanRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> operation)Produces a collection containing cumulative results of applying the operator from right to left.default intsearch(T element)Searches this sequence for a specific element using a linear search.default intsearch(T element, @NonNull java.util.Comparator<? super T> comparator)Searches this sequence for a specific element using a linear search.default intsegmentLength(@NonNull java.util.function.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.LinearSeq<T>shuffle()Returns a new sequence with the elements randomly shuffled.LinearSeq<T>slice(int beginIndex, int endIndex)Returns a subsequence (slice) of this sequence, starting atbeginIndex(inclusive) and ending atendIndex(exclusive).Iterator<? extends LinearSeq<T>>slideBy(@NonNull java.util.function.Function<? super T,?> classifier)Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Iterator<? extends LinearSeq<T>>sliding(int size)Slides a window of a givensizeover thisTraversablewith a step size of 1.Iterator<? extends LinearSeq<T>>sliding(int size, int step)Slides a window of a specificsizewith a givenstepover thisTraversable.<U> LinearSeq<T>sortBy(@NonNull java.util.Comparator<? super U> comparator, java.util.function.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 java.lang.Comparable<? super U>>
LinearSeq<T>sortBy(@NonNull java.util.function.Function<? super T,? extends U> mapper)Returns a new sequence sorted by comparing elements in a different domain defined by the givenmapper.LinearSeq<T>sorted()Returns a new sequence with elements sorted according to their natural order.LinearSeq<T>sorted(@NonNull java.util.Comparator<? super T> comparator)Returns a new sequence with elements sorted according to the givenComparator.Tuple2<? extends LinearSeq<T>,? extends LinearSeq<T>>span(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto a prefix and remainder according to the givenpredicate.LinearSeq<T>subSequence(int beginIndex)Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndexand extending to the end of this sequence.LinearSeq<T>subSequence(int beginIndex, int endIndex)Returns aSeqthat is a subsequence of this sequence, starting from the specifiedbeginIndex(inclusive) and ending atendIndex(exclusive).LinearSeq<T>tail()Returns a newTraversablewithout its first element.Option<? extends LinearSeq<T>>tailOption()Returns a newTraversablewithout its first element as anOption.LinearSeq<T>take(int n)Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.LinearSeq<T>takeRight(int n)Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.LinearSeq<T>takeRightUntil(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from the end of the sequence until an element satisfies the given predicate.LinearSeq<T>takeRightWhile(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from the end of the sequence while the given predicate holds.LinearSeq<T>takeUntil(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversableuntil the given predicate holds for an element.LinearSeq<T>takeWhile(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversablewhile the given predicate holds.<T1,T2>
Tuple2<? extends LinearSeq<T1>,? extends LinearSeq<T2>>unzip(@NonNull java.util.function.Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)Unzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.LinearSeq<T>update(int index, @NonNull java.util.function.Function<? super T,? extends T> updater)Returns a newSeqwith the element at the specified index updated using the given function.LinearSeq<T>update(int index, T element)Returns a newSeqwith the element at the specified index replaced by the given value.<U> LinearSeq<Tuple2<T,U>>zip(@NonNull java.lang.Iterable<? extends U> that)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable.<U> LinearSeq<Tuple2<T,U>>zipAll(@NonNull java.lang.Iterable<? extends U> that, T thisElem, U thatElem)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.<U,R>
LinearSeq<R>zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)Returns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function.LinearSeq<Tuple2<T,java.lang.Integer>>zipWithIndex()Zips thisTraversablewith its indices, starting at 0.<U> LinearSeq<U>zipWithIndex(@NonNull java.util.function.BiFunction<? super T,? super java.lang.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, reduceOption
-
Methods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupled
-
Methods inherited from interface io.vavr.collection.Seq
apply, asJava, asJavaMutable, containsSlice, crossProduct, crossProduct, endsWith, foldRight, get, indexOf, indexOf, indexOfOption, indexOfOption, indexOfSlice, indexOfSliceOption, indexOfSliceOption, indexWhere, indexWhereOption, indexWhereOption, isSequential, iterator, lastIndexOf, lastIndexOf, lastIndexOfOption, lastIndexOfOption, lastIndexOfSlice, lastIndexOfSliceOption, lastIndexOfSliceOption, lastIndexWhere, lastIndexWhereOption, lastIndexWhereOption, leftPadTo, lift, prefixLength, splitAt, splitAt, splitAtInclusive, startsWith, startsWith, unzip3, withDefault, withDefaultValue
-
Methods 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, sum
-
Methods 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 Detail
-
serialVersionUID
static final long serialVersionUID
The serial version UID for serialization.- See Also:
- Constant Field Values
-
-
Method Detail
-
narrow
static <T> LinearSeq<T> narrow(LinearSeq<? extends T> linearSeq)
Narrows a widenedLinearSeq<? extends T>toLinearSeq<T>by performing a type-safe cast. This is eligible because immutable/read-only collections are covariant.- Type Parameters:
T- Component type of theLinearSeq.- Parameters:
linearSeq- ALinearSeq.- Returns:
- the given
linearSeqinstance as narrowed typeLinearSeq<T>.
-
append
LinearSeq<T> append(T element)
Description copied from interface:SeqReturns a new sequence with the given element appended at the end.
-
appendAll
LinearSeq<T> appendAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SeqReturns a new sequence with all elements from the givenIterableappended at the end of this sequence.
-
asJava
@GwtIncompatible LinearSeq<T> asJava(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)
Description copied from interface:SeqCreates an immutableListview of thisSeqand passes it to the givenaction.The view is immutable: any attempt to modify it will throw
UnsupportedOperationExceptionat runtime.- Specified by:
asJavain interfaceSeq<T>- Parameters:
action- a side-effecting operation that receives an immutablejava.util.Listview- Returns:
- this sequence
- See Also:
Seq.asJava()
-
asJavaMutable
@GwtIncompatible LinearSeq<T> asJavaMutable(@NonNull java.util.function.Consumer<? super java.util.List<T>> action)
Description copied from interface:SeqCreates 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.
- Specified by:
asJavaMutablein interfaceSeq<T>- 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:
Seq.asJavaMutable()
-
asPartialFunction
default PartialFunction<java.lang.Integer,T> asPartialFunction() throws java.lang.IndexOutOfBoundsException
Description copied from interface:SeqReturns 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.- Specified by:
asPartialFunctionin interfaceSeq<T>- Returns:
- a
PartialFunctionmapping indices to elements - Throws:
java.lang.IndexOutOfBoundsException- if the sequence is empty, or ifindex < 0orindex >= length()
-
collect
<R> LinearSeq<R> collect(@NonNull PartialFunction<? super T,? extends R> partialFunction)
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 interfaceSeq<T>- 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
LinearSeq<? extends LinearSeq<T>> combinations()
Description copied from interface:SeqReturns 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 ]- Specified by:
combinationsin interfaceSeq<T>- Returns:
- a sequence of sequences representing all combinations of this sequence's elements
-
combinations
LinearSeq<? extends LinearSeq<T>> combinations(int k)
Description copied from interface:SeqReturns all subsets of this sequence containing exactlykdistinct elements, i.e., the k-combinations of this sequence.- Specified by:
combinationsin interfaceSeq<T>- Parameters:
k- the size of each subset- Returns:
- a sequence of sequences representing all k-element combinations
- See Also:
- Combination
-
crossProduct
Iterator<? extends LinearSeq<T>> crossProduct(int power)
Description copied from interface:SeqReturns 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);- Specified by:
crossProductin interfaceSeq<T>- Parameters:
power- the number of Cartesian multiplications- Returns:
- an
Iteratorover sequences representing the Cartesian power of this sequence
-
distinct
LinearSeq<T> distinct()
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance with all duplicates removed. Element equality is determined usingequals.
-
distinctBy
LinearSeq<T> distinctBy(@NonNull java.util.Comparator<? super T> comparator)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.- Specified by:
distinctByin interfaceSeq<T>- Specified by:
distinctByin interfaceTraversable<T>- Parameters:
comparator- a comparator used to determine equality of elements- Returns:
- a new
Traversablewith duplicates removed
-
distinctBy
<U> LinearSeq<T> distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)
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 interfaceSeq<T>- 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
LinearSeq<T> distinctByKeepLast(@NonNull java.util.Comparator<? super T> comparator)
Description copied from interface:SeqReturns a sequence with duplicate elements removed, as determined by the provided comparator. When duplicates are found, the **last occurrence** of each element is retained.- Specified by:
distinctByKeepLastin interfaceSeq<T>- Parameters:
comparator- a comparator defining equality between elements- Returns:
- a new sequence with duplicates removed, keeping the last occurrence of each element
-
distinctByKeepLast
<U> LinearSeq<T> distinctByKeepLast(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)
Description copied from interface:SeqReturns 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.- Specified by:
distinctByKeepLastin interfaceSeq<T>- 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
LinearSeq<T> drop(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.
-
dropUntil
LinearSeq<T> dropUntil(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.
-
dropWhile
LinearSeq<T> dropWhile(@NonNull java.util.function.Predicate<? super T> predicate)
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.
-
dropRight
LinearSeq<T> dropRight(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.
-
dropRightUntil
LinearSeq<T> dropRightUntil(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:SeqDrops 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.- Specified by:
dropRightUntilin interfaceSeq<T>- 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
-
dropRightWhile
LinearSeq<T> dropRightWhile(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:SeqDrops 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.- Specified by:
dropRightWhilein interfaceSeq<T>- 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
-
filter
LinearSeq<T> filter(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.
-
reject
LinearSeq<T> reject(@NonNull java.util.function.Predicate<? super T> predicate)
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()).
-
flatMap
<U> LinearSeq<U> flatMap(@NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
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 interfaceSeq<T>- 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
-
groupBy
<C> Map<C,? extends LinearSeq<T>> groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceSeq<T>- 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:
Traversable.arrangeBy(Function)
-
grouped
Iterator<? extends LinearSeq<T>> grouped(int size)
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). - If empty, the resulting
-
indexOfSlice
default int indexOfSlice(@NonNull java.lang.Iterable<? extends T> that, int from)
Description copied from interface:SeqReturns 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.
- Specified by:
indexOfSlicein interfaceSeq<T>- 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
-
indexWhere
default int indexWhere(@NonNull java.util.function.Predicate<? super T> predicate, int from)
Description copied from interface:SeqReturns the index of the first element at or after the specified start index that satisfies the given predicate, or-1if no such element exists.- Specified by:
indexWherein interfaceSeq<T>- 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
-
init
LinearSeq<T> init()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one.This is the dual of
Traversable.tail().
-
initOption
Option<? extends LinearSeq<T>> 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 interfaceSeq<T>- Specified by:
initOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, orNoneif this Traversable is empty
-
insert
LinearSeq<T> insert(int index, T element)
Description copied from interface:SeqReturns a new sequence with the given element inserted at the specified index.
-
insertAll
LinearSeq<T> insertAll(int index, @NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SeqReturns a new sequence with the given elements inserted at the specified index.
-
intersperse
LinearSeq<T> intersperse(T element)
Description copied from interface:SeqReturns a new sequence where the given element is inserted between all elements of this sequence.- Specified by:
interspersein interfaceSeq<T>- Parameters:
element- the element to intersperse- Returns:
- a new
Seqwith the element interspersed
-
isDefinedAt
@Deprecated default boolean isDefinedAt(java.lang.Integer index)
Deprecated.Description copied from interface:PartialFunctionTests whether a value is contained in the function's domain.- Specified by:
isDefinedAtin interfacePartialFunction<java.lang.Integer,T>- Parameters:
index- a potential input to the function- Returns:
trueif the given value is contained in the function's domain,falseotherwise
-
lastIndexOfSlice
default int lastIndexOfSlice(@NonNull java.lang.Iterable<? extends T> that, int end)
Description copied from interface:SeqReturns 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.- Specified by:
lastIndexOfSlicein interfaceSeq<T>- 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
-
lastIndexWhere
default int lastIndexWhere(@NonNull java.util.function.Predicate<? super T> predicate, int end)
Description copied from interface:SeqReturns the index of the last element at or before the specified end index that satisfies the given predicate, or-1if no such element exists.- Specified by:
lastIndexWherein interfaceSeq<T>- 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
-
map
<U> LinearSeq<U> map(@NonNull java.util.function.Function<? super T,? extends U> mapper)
Description copied from interface:TraversableTransforms the elements of this Traversable to a new type, preserving order if defined.
-
mapTo
default <U> LinearSeq<U> mapTo(U value)
Description copied from interface:ValueMaps the underlying value to another fixed value.
-
mapToVoid
default LinearSeq<java.lang.Void> mapToVoid()
Description copied from interface:ValueMaps the underlying value to Void
-
orElse
LinearSeq<T> orElse(@NonNull java.lang.Iterable<? extends T> other)
Description copied from interface:TraversableReturns thisTraversableif it is non-empty; otherwise, returns the given alternative.
-
orElse
LinearSeq<T> orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Description copied from interface:TraversableReturns thisTraversableif it is non-empty; otherwise, returns the result of evaluating the given supplier.
-
padTo
LinearSeq<T> padTo(int length, T element)
Description copied from interface:SeqReturns 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.
-
patch
LinearSeq<T> patch(int from, @NonNull java.lang.Iterable<? extends T> that, int replaced)
Description copied from interface:SeqReturns a new sequence in which a slice of elements in this sequence is replaced by the elements of another sequence.
-
partition
Tuple2<? extends LinearSeq<T>,? extends LinearSeq<T>> partition(@NonNull java.util.function.Predicate<? super T> predicate)
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.
-
peek
LinearSeq<T> peek(@NonNull java.util.function.Consumer<? super T> action)
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.
-
permutations
LinearSeq<? extends LinearSeq<T>> permutations()
Description copied from interface:SeqReturns 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] ]- Specified by:
permutationsin interfaceSeq<T>- Returns:
- a sequence of all unique permutations of this sequence
-
prepend
LinearSeq<T> prepend(T element)
Description copied from interface:SeqReturns a new sequence with the given element prepended to this sequence.
-
prependAll
LinearSeq<T> prependAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SeqReturns a new sequence with all given elements prepended to this sequence.- Specified by:
prependAllin interfaceSeq<T>- Parameters:
elements- the elements to prepend; must not benull- Returns:
- a new
Seqwith the elements added at the front
-
remove
LinearSeq<T> remove(T element)
Description copied from interface:SeqReturns a new sequence with the first occurrence of the given element removed.
-
removeFirst
LinearSeq<T> removeFirst(@NonNull java.util.function.Predicate<T> predicate)
Description copied from interface:SeqReturns a new sequence with the first element that satisfies the given predicate removed.- Specified by:
removeFirstin interfaceSeq<T>- Parameters:
predicate- the predicate used to identify the element to remove; must not benull- Returns:
- a new
Seqwithout the first matching element
-
removeLast
LinearSeq<T> removeLast(@NonNull java.util.function.Predicate<T> predicate)
Description copied from interface:SeqReturns a new sequence with the last element that satisfies the given predicate removed.- Specified by:
removeLastin interfaceSeq<T>- Parameters:
predicate- the predicate used to identify the element to remove; must not benull- Returns:
- a new
Seqwithout the last matching element
-
removeAt
LinearSeq<T> removeAt(int index)
Description copied from interface:SeqReturns a new sequence with the element at the specified position removed. Subsequent elements are shifted to the left (indices decreased by one).
-
removeAll
LinearSeq<T> removeAll(T element)
Description copied from interface:SeqReturns a new sequence with all occurrences of the given element removed.
-
removeAll
LinearSeq<T> removeAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SeqReturns a new sequence with all occurrences of the given elements removed.
-
removeAll
@Deprecated LinearSeq<T> removeAll(@NonNull java.util.function.Predicate<? super T> predicate)
Deprecated.Description copied from interface:SeqReturns a new Seq consisting of all elements which do not satisfy the given predicate.
-
replace
LinearSeq<T> replace(T currentElement, T newElement)
Description copied from interface:TraversableReplaces the first occurrence ofcurrentElementwithnewElement, if it exists.
-
replaceAll
LinearSeq<T> replaceAll(T currentElement, T newElement)
Description copied from interface:TraversableReplaces all occurrences ofcurrentElementwithnewElement.- Specified by:
replaceAllin interfaceSeq<T>- 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
LinearSeq<T> retainAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:TraversableRetains only the elements from this Traversable that are contained in the givenelements.
-
reverse
LinearSeq<T> reverse()
Description copied from interface:SeqReturns a new sequence with the order of elements reversed.
-
reverseIterator
default Iterator<T> reverseIterator()
Description copied from interface:SeqReturns an iterator that yields elements of this sequence in reversed order.Note:
xs.reverseIterator()is equivalent toxs.reverse().iterator()but may be more efficient.- Specified by:
reverseIteratorin interfaceSeq<T>- Returns:
- an
Iteratorover the elements in reversed order
-
rotateLeft
LinearSeq<T> rotateLeft(int n)
Description copied from interface:SeqReturns 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);- Specified by:
rotateLeftin interfaceSeq<T>- Parameters:
n- the number of positions to rotate left- Returns:
- a new
Seqwith elements rotated left
-
rotateRight
LinearSeq<T> rotateRight(int n)
Description copied from interface:SeqReturns 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);- Specified by:
rotateRightin interfaceSeq<T>- Parameters:
n- the number of positions to rotate right- Returns:
- a new
Seqwith elements rotated right
-
shuffle
LinearSeq<T> shuffle()
Description copied from interface:SeqReturns a new sequence with the elements randomly shuffled.
-
scan
LinearSeq<T> scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Description copied from interface:TraversableComputes a prefix scan of the elements of this Traversable.The neutral element
zeromay be applied more than once.
-
scanLeft
<U> LinearSeq<U> scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super T,? extends U> operation)
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 interfaceSeq<T>- 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
<U> LinearSeq<U> scanRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> operation)
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 interfaceSeq<T>- 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
-
segmentLength
default int segmentLength(@NonNull java.util.function.Predicate<? super T> predicate, int from)
Description copied from interface:SeqReturns 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.
- Specified by:
segmentLengthin interfaceSeq<T>- 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
-
slice
LinearSeq<T> slice(int beginIndex, int endIndex)
Description copied from interface:SeqReturns 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
Seq.subSequence(int, int), which may throw an exception instead of returning a sequence in some cases.
-
slideBy
Iterator<? extends LinearSeq<T>> slideBy(@NonNull java.util.function.Function<? super T,?> classifier)
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]]
-
sliding
Iterator<? extends LinearSeq<T>> sliding(int size)
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.
-
sliding
Iterator<? extends LinearSeq<T>> sliding(int size, int step)
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]]
-
sorted
LinearSeq<T> sorted()
Description copied from interface:SeqReturns a new sequence with elements sorted according to their natural order.
-
sorted
LinearSeq<T> sorted(@NonNull java.util.Comparator<? super T> comparator)
Description copied from interface:SeqReturns a new sequence with elements sorted according to the givenComparator.
-
sortBy
<U extends java.lang.Comparable<? super U>> LinearSeq<T> sortBy(@NonNull java.util.function.Function<? super T,? extends U> mapper)
Description copied from interface:SeqReturns a new sequence sorted by comparing elements in a different domain defined by the givenmapper.
-
sortBy
<U> LinearSeq<T> sortBy(@NonNull java.util.Comparator<? super U> comparator, java.util.function.Function<? super T,? extends U> mapper)
Description copied from interface:SeqReturns a new sequence sorted by comparing elements in a different domain defined by the givenmapper, using the providedcomparator.- Specified by:
sortByin interfaceSeq<T>- 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
-
span
Tuple2<? extends LinearSeq<T>,? extends LinearSeq<T>> span(@NonNull java.util.function.Predicate<? super T> predicate)
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.
-
subSequence
LinearSeq<T> subSequence(int beginIndex)
Description copied from interface:SeqReturns 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
Seq.drop(int), which provides similar functionality but does not throw an exception for out-of-bounds indices.- Specified by:
subSequencein interfaceSeq<T>- Parameters:
beginIndex- the starting index (inclusive) of the subsequence- Returns:
- a new
Seqrepresenting the subsequence frombeginIndexto the end
-
subSequence
LinearSeq<T> subSequence(int beginIndex, int endIndex)
Description copied from interface:SeqReturns 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
Seq.slice(int, int), which returns an empty sequence instead of throwing exceptions when indices are out of range.- Specified by:
subSequencein interfaceSeq<T>- Parameters:
beginIndex- the starting index (inclusive) of the subsequenceendIndex- the ending index (exclusive) of the subsequence- Returns:
- a new
Seqrepresenting the subsequence frombeginIndextoendIndex - 1
-
tail
LinearSeq<T> tail()
Description copied from interface:TraversableReturns a newTraversablewithout its first element.
-
tailOption
Option<? extends LinearSeq<T>> tailOption()
Description copied from interface:TraversableReturns a newTraversablewithout its first element as anOption.- Specified by:
tailOptionin interfaceSeq<T>- Specified by:
tailOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, otherwiseNone
-
take
LinearSeq<T> take(int n)
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.
-
takeUntil
LinearSeq<T> takeUntil(@NonNull java.util.function.Predicate<? super T> predicate)
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.
-
takeWhile
LinearSeq<T> takeWhile(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableTakes elements from thisTraversablewhile the given predicate holds.
-
takeRight
LinearSeq<T> takeRight(int n)
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.
-
takeRightUntil
LinearSeq<T> takeRightUntil(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:SeqTakes 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.- Specified by:
takeRightUntilin interfaceSeq<T>- 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
-
takeRightWhile
LinearSeq<T> takeRightWhile(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:SeqTakes 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.- Specified by:
takeRightWhilein interfaceSeq<T>- 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
-
unzip
<T1,T2> Tuple2<? extends LinearSeq<T1>,? extends LinearSeq<T2>> unzip(@NonNull java.util.function.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 interfaceSeq<T>- 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
-
update
LinearSeq<T> update(int index, T element)
Description copied from interface:SeqReturns a newSeqwith the element at the specified index replaced by the given value.
-
update
LinearSeq<T> update(int index, @NonNull java.util.function.Function<? super T,? extends T> updater)
Description copied from interface:SeqReturns a newSeqwith the element at the specified index updated using the given function.
-
zip
<U> LinearSeq<Tuple2<T,U>> zip(@NonNull java.lang.Iterable<? extends U> that)
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 interfaceSeq<T>- 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> LinearSeq<R> zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.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 interfaceSeq<T>- 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
<U> LinearSeq<Tuple2<T,U>> zipAll(@NonNull java.lang.Iterable<? extends U> that, T thisElem, U thatElem)
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 interfaceSeq<T>- 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
LinearSeq<Tuple2<T,java.lang.Integer>> zipWithIndex()
Description copied from interface:TraversableZips thisTraversablewith its indices, starting at 0.- Specified by:
zipWithIndexin interfaceSeq<T>- Specified by:
zipWithIndexin interfaceTraversable<T>- Returns:
- a new
Traversablecontaining each element paired with its index
-
zipWithIndex
<U> LinearSeq<U> zipWithIndex(@NonNull java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
Description copied from interface:TraversableZips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.- Specified by:
zipWithIndexin interfaceSeq<T>- 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
-
search
default int search(T element)
Searches this sequence for a specific element using a linear search. The sequence must already be sorted into ascending natural order. If it is not sorted, the results are undefined.- Specified by:
searchin interfaceSeq<T>- Parameters:
element- the element to find- Returns:
- the index of the search element, if it is contained in the sequence;
otherwise,
(-(insertion point) - 1). The insertion point is defined as the point at which the element would be inserted into the sequence. Note that this guarantees that the return value will be >= 0 if and only if the element is found. - Throws:
java.lang.ClassCastException- if T cannot be cast toComparable<? super T>
-
search
default int search(T element, @NonNull java.util.Comparator<? super T> comparator)
Searches this sequence for a specific element using a linear search. The sequence must already be sorted into ascending order according to the specified comparator. If it is not sorted, the results are undefined.- Specified by:
searchin interfaceSeq<T>- Parameters:
element- the element to findcomparator- the comparator by which this sequence is ordered- Returns:
- the index of the search element, if it is contained in the sequence;
otherwise,
(-(insertion point) - 1). The insertion point is defined as the point at which the element would be inserted into the sequence. Note that this guarantees that the return value will be >= 0 if and only if the element is found.
-
-