Class Array<T>
- Type Parameters:
T- Component type
- All Implemented Interfaces:
Foldable<T>,IndexedSeq<T>,Seq<T>,Traversable<T>,Function1<Integer,,T> PartialFunction<Integer,,T> Value<T>,Serializable,Iterable<T>,Function<Integer,T>
Object[] containing elements of type T.- Author:
- Ruslan Sennov, Daniel Dietrich
- See Also:
-
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.asJava()Returns an immutableListview of thisSeq.Returns a mutableListview of thisSeq.asJavaMutable(@NonNull Consumer<? super List<T>> action) <R> Array<R> collect(@NonNull PartialFunction<? super T, ? extends R> partialFunction) Applies aPartialFunctionto all elements that are defined for it and collects the results.Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aArray.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.crossProduct(int power) Returns the n-ary Cartesian power (cross product) of this sequence.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.static <T> Array<T> empty()Returns the empty Array.booleanDetermines whether this collection is equal to the given object.static <T> Array<T> Returns an Array containingnvalues supplied by a given Suppliers.static <T> Array<T> fill(int n, T element) Returns an Array containingntimes the givenelementReturns a new traversable containing only the elements that satisfy the given predicate.<U> Array<U> Transforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.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.booleanIndicates whether thisTraversablehas a known finite size.inthashCode()Returns the hash code of this collection.head()Returns the first element of this non-emptyTraversable.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.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.booleanisAsync()AnArrayis computed synchronously.booleanisEmpty()Checks if this Traversable contains no elements.booleanisLazy()AnArrayis computed eagerly.booleanChecks if this Traversable can be traversed multiple times without side effects.iterator()Returns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail().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.Returns a new sequence with this sequence padded on the left with the given element until the specified target length is reached.intlength()Returns the number of elements in this Traversable.<U> Array<U> Transforms the elements of this Traversable to a new type, preserving order if defined.<U> Array<U> mapTo(U value) Maps the underlying value to another fixed value.Maps the underlying value to Voidstatic <T> Array<T> Narrows aArray<? extends T>toArray<T>via a type-safe cast.static <T> Array<T> of(T element) Returns a singletonArray, i.e. aArrayof one element.static <T> Array<T> of(T @NonNull ... elements) Creates an Array of the given elements.ofAll(boolean @NonNull ... elements) Creates an Array from boolean values.ofAll(byte @NonNull ... elements) Creates an Array from byte values.ofAll(char @NonNull ... elements) Creates an Array from char values.ofAll(double @NonNull ... elements) Creates an Array from double values.ofAll(float @NonNull ... elements) Creates an Array from float values.ofAll(int @NonNull ... elements) Creates an Array from int values.ofAll(long @NonNull ... elements) Creates an Array from long values.ofAll(short @NonNull ... elements) Creates an Array from short values.static <T> Array<T> Creates an Array of the given elements.static <T> Array<T> Creates an Array that contains the elements of the givenStream.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.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.range(char from, char toExclusive) Creates an Array of char numbers starting fromfrom, extending totoExclusive - 1.range(int from, int toExclusive) Creates an Array of int numbers starting fromfrom, extending totoExclusive - 1.range(long from, long toExclusive) Creates an Array of long numbers starting fromfrom, extending totoExclusive - 1.rangeBy(char from, char toExclusive, int step) Creates an Array of char numbers starting fromfrom, extending totoExclusive - 1, withstep.rangeBy(double from, double toExclusive, double step) Creates an Array of double numbers starting fromfrom, extending totoExclusive - 1, withstep.rangeBy(int from, int toExclusive, int step) Creates an Array of int numbers starting fromfrom, extending totoExclusive - 1, withstep.rangeBy(long from, long toExclusive, long step) Creates an Array of long numbers starting fromfrom, extending totoExclusive - 1, withstep.rangeClosed(char from, char toInclusive) Creates an Array of char numbers starting fromfrom, extending totoInclusive.rangeClosed(int from, int toInclusive) Creates an Array of int numbers starting fromfrom, extending totoInclusive.rangeClosed(long from, long toInclusive) Creates an Array of long numbers starting fromfrom, extending totoInclusive.rangeClosedBy(char from, char toInclusive, int step) Creates an Array of char numbers starting fromfrom, extending totoInclusive, withstep.rangeClosedBy(double from, double toInclusive, double step) Creates an Array of double numbers starting fromfrom, extending totoInclusive, withstep.rangeClosedBy(int from, int toInclusive, int step) Creates an Array of int numbers starting fromfrom, extending totoInclusive, withstep.rangeClosedBy(long from, long toInclusive, long step) Creates an Array of long numbers starting fromfrom, extending totoInclusive, withstep.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.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.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> Array<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> Array<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.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>>
Array<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.Returns the name of this Value type, which is used by toString().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).static <T> Array<T> Returns an Array containingnvalues of a given Functionfover a range of integer values from 0 ton - 1.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.toString()Clarifies that values have a proper toString() method implemented.<U> UTransforms thisArray.static <T> Array<T> Creates an Array from a seed value and a function.static <T,U> Array <U> unfoldLeft(T seed, Function<? super T, Option<Tuple2<? extends T, ? extends U>>> f) Creates an Array from a seed value and a function.static <T,U> Array <U> unfoldRight(T seed, Function<? super T, Option<Tuple2<? extends U, ? extends T>>> f) Creates an Array from a seed value and a function.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.Returns 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> Array <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> Array<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 class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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.collection.IndexedSeq
asPartialFunction, endsWith, indexOfSlice, indexWhere, isDefinedAt, last, lastIndexOfSlice, lastIndexWhere, reverseIterator, search, search, segmentLength, startsWithMethods inherited from interface io.vavr.collection.Seq
apply, containsSlice, crossProduct, crossProduct, foldRight, indexOf, indexOfOption, indexOfOption, indexOfSlice, indexOfSliceOption, indexOfSliceOption, indexWhere, indexWhereOption, indexWhereOption, isSequential, iterator, lastIndexOf, lastIndexOfOption, lastIndexOfOption, lastIndexOfSlice, lastIndexOfSliceOption, lastIndexOfSliceOption, lastIndexWhere, lastIndexWhereOption, lastIndexWhereOption, lift, prefixLength, startsWith, withDefault, withDefaultValueMethods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, headOption, isDistinct, isOrdered, isSingleValued, lastOption, 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, out, out, stderr, stdout, 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, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVector
-
Method Details
-
collector
Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aArray.- Type Parameters:
T- Component type of the Array.- Returns:
- A
ArrayCollector.
-
empty
Returns the empty Array.- Type Parameters:
T- Component type- Returns:
- The empty Array.
-
narrow
Narrows aArray<? extends T>toArray<T>via a type-safe cast. Safe here because the array is immutable and no elements can be added that would violate the type (covariance)- Type Parameters:
T- the target element type- Parameters:
array- the array to narrow- Returns:
- the same array viewed as
Array<T>
-
of
Returns a singletonArray, i.e. aArrayof one element.- Type Parameters:
T- The component type- Parameters:
element- An element.- Returns:
- A new Array instance containing the given element
-
of
Creates an Array of the given elements.- Type Parameters:
T- Component type of the Array.- Parameters:
elements- Zero or more elements.- Returns:
- An Array containing the given elements in the same order.
- Throws:
NullPointerException- ifelementsis null
-
ofAll
Creates an Array of the given elements.If the iteration order of the given elements is stable, the resulting Array will maintain that same order.
- Type Parameters:
T- Component type of the Array.- Parameters:
elements- An Iterable of elements.- Returns:
- An Array containing the given elements in the same order.
- Throws:
NullPointerException- ifelementsis null
-
ofAll
Creates an Array that contains the elements of the givenStream.- Type Parameters:
T- Component type of the Stream.- Parameters:
javaStream- AStream- Returns:
- An Array containing the given elements in the same order.
-
ofAll
Creates an Array from boolean values.- Parameters:
elements- boolean values- Returns:
- A new Array of Boolean values
- Throws:
NullPointerException- if elements is null
-
ofAll
Creates an Array from byte values.- Parameters:
elements- byte values- Returns:
- A new Array of Byte values
- Throws:
NullPointerException- if elements is null
-
ofAll
Creates an Array from char values.- Parameters:
elements- char values- Returns:
- A new Array of Character values
- Throws:
NullPointerException- if elements is null
-
ofAll
Creates an Array from double values.- Parameters:
elements- double values- Returns:
- A new Array of Double values
- Throws:
NullPointerException- if elements is null
-
ofAll
Creates an Array from float values.- Parameters:
elements- float values- Returns:
- A new Array of Float values
- Throws:
NullPointerException- if elements is null
-
ofAll
Creates an Array from int values.- Parameters:
elements- int values- Returns:
- A new Array of Integer values
- Throws:
NullPointerException- if elements is null
-
ofAll
Creates an Array from long values.- Parameters:
elements- long values- Returns:
- A new Array of Long values
- Throws:
NullPointerException- if elements is null
-
ofAll
Creates an Array from short values.- Parameters:
elements- short values- Returns:
- A new Array of Short values
- Throws:
NullPointerException- if elements is null
-
tabulate
Returns an Array containingnvalues of a given Functionfover a range of integer values from 0 ton - 1.- Type Parameters:
T- Component type of the Array- Parameters:
n- The number of elements in the Arrayf- The Function computing element values- Returns:
- An Array consisting of elements
f(0),f(1), ..., f(n - 1) - Throws:
NullPointerException- iffis null
-
fill
Returns an Array containingnvalues supplied by a given Suppliers.- Type Parameters:
T- Component type of the Array- Parameters:
n- The number of elements in the Arrays- The Supplier computing element values- Returns:
- An Array of size
n, where each element contains the result supplied bys. - Throws:
NullPointerException- ifsis null
-
fill
Returns an Array containingntimes the givenelement- Type Parameters:
T- Component type of the Array- Parameters:
n- The number of elements in the Arrayelement- The element- Returns:
- An Array of size
n, where each element is the givenelement.
-
range
Creates an Array of char numbers starting fromfrom, extending totoExclusive - 1.Examples:
Array.range('a', 'a') // = Array() Array.range('c', 'a') // = Array() Array.range('a', 'd') // = Array('a', 'b', 'c')- Parameters:
from- the first chartoExclusive- the last char + 1- Returns:
- a range of char values as specified or the empty range if
from >= toExclusive
-
rangeBy
Creates an Array of char numbers starting fromfrom, extending totoExclusive - 1, withstep.Examples:
Array.rangeBy('a', 'c', 1) // = Array('a', 'b') Array.rangeBy('a', 'd', 2) // = Array('a', 'c') Array.rangeBy('d', 'a', -2) // = Array('d', 'b') Array.rangeBy('d', 'a', 2) // = Array()- Parameters:
from- the first chartoExclusive- the last char + 1step- the step- Returns:
- a range of char values as specified or the empty range if
from >= toInclusiveandstep > 0or
from <= toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
rangeBy
Creates an Array of double numbers starting fromfrom, extending totoExclusive - 1, withstep.Examples:
Array.rangeBy(1.0, 3.0, 1.0) // = Array(1.0, 2.0) Array.rangeBy(1.0, 4.0, 2.0) // = Array(1.0, 3.0) Array.rangeBy(4.0, 1.0, -2.0) // = Array(4.0, 2.0) Array.rangeBy(4.0, 1.0, 2.0) // = Array()- Parameters:
from- the first doubletoExclusive- the last double + 1step- the step- Returns:
- a range of double values as specified or the empty range if
from >= toInclusiveandstep > 0or
from <= toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
range
Creates an Array of int numbers starting fromfrom, extending totoExclusive - 1.Examples:
Array.range(0, 0) // = Array() Array.range(2, 0) // = Array() Array.range(-2, 2) // = Array(-2, -1, 0, 1)- Parameters:
from- the first numbertoExclusive- the last number + 1- Returns:
- a range of int values as specified or the empty range if
from >= toExclusive
-
rangeBy
Creates an Array of int numbers starting fromfrom, extending totoExclusive - 1, withstep.Examples:
Array.rangeBy(1, 3, 1) // = Array(1, 2) Array.rangeBy(1, 4, 2) // = Array(1, 3) Array.rangeBy(4, 1, -2) // = Array(4, 2) Array.rangeBy(4, 1, 2) // = Array()- Parameters:
from- the first numbertoExclusive- the last number + 1step- the step- Returns:
- a range of long values as specified or the empty range if
from >= toInclusiveandstep > 0or
from <= toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
range
Creates an Array of long numbers starting fromfrom, extending totoExclusive - 1.Examples:
Array.range(0L, 0L) // = Array() Array.range(2L, 0L) // = Array() Array.range(-2L, 2L) // = Array(-2L, -1L, 0L, 1L)- Parameters:
from- the first numbertoExclusive- the last number + 1- Returns:
- a range of long values as specified or the empty range if
from >= toExclusive
-
rangeBy
Creates an Array of long numbers starting fromfrom, extending totoExclusive - 1, withstep.Examples:
Array.rangeBy(1L, 3L, 1L) // = Array(1L, 2L) Array.rangeBy(1L, 4L, 2L) // = Array(1L, 3L) Array.rangeBy(4L, 1L, -2L) // = Array(4L, 2L) Array.rangeBy(4L, 1L, 2L) // = Array()- Parameters:
from- the first numbertoExclusive- the last number + 1step- the step- Returns:
- a range of long values as specified or the empty range if
from >= toInclusiveandstep > 0or
from <= toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
rangeClosed
Creates an Array of char numbers starting fromfrom, extending totoInclusive.Examples:
Array.rangeClosed('a', 'a') // = Array('a') Array.rangeClosed('c', 'a') // = Array() Array.rangeClosed('a', 'c') // = Array('a', 'b', 'c')- Parameters:
from- the first chartoInclusive- the last char- Returns:
- a range of char values as specified or the empty range if
from > toInclusive
-
rangeClosedBy
Creates an Array of char numbers starting fromfrom, extending totoInclusive, withstep.Examples:
Array.rangeClosedBy('a', 'c', 1) // = Array('a', 'b', 'c') Array.rangeClosedBy('a', 'd', 2) // = Array('a', 'c') Array.rangeClosedBy('d', 'a', -2) // = Array('d', 'b') Array.rangeClosedBy('d', 'a', 2) // = Array()- Parameters:
from- the first chartoInclusive- the last charstep- the step- Returns:
- a range of char values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
rangeClosedBy
@GwtIncompatible public static Array<Double> rangeClosedBy(double from, double toInclusive, double step) Creates an Array of double numbers starting fromfrom, extending totoInclusive, withstep.Examples:
Array.rangeClosedBy(1.0, 3.0, 1.0) // = Array(1.0, 2.0, 3.0) Array.rangeClosedBy(1.0, 4.0, 2.0) // = Array(1.0, 3.0) Array.rangeClosedBy(4.0, 1.0, -2.0) // = Array(4.0, 2.0) Array.rangeClosedBy(4.0, 1.0, 2.0) // = Array()- Parameters:
from- the first doubletoInclusive- the last doublestep- the step- Returns:
- a range of double values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
rangeClosed
Creates an Array of int numbers starting fromfrom, extending totoInclusive.Examples:
Array.rangeClosed(0, 0) // = Array(0) Array.rangeClosed(2, 0) // = Array() Array.rangeClosed(-2, 2) // = Array(-2, -1, 0, 1, 2)- Parameters:
from- the first numbertoInclusive- the last number- Returns:
- a range of int values as specified or the empty range if
from > toInclusive
-
rangeClosedBy
Creates an Array of int numbers starting fromfrom, extending totoInclusive, withstep.Examples:
Array.rangeClosedBy(1, 3, 1) // = Array(1, 2, 3) Array.rangeClosedBy(1, 4, 2) // = Array(1, 3) Array.rangeClosedBy(4, 1, -2) // = Array(4, 2) Array.rangeClosedBy(4, 1, 2) // = Array()- Parameters:
from- the first numbertoInclusive- the last numberstep- the step- Returns:
- a range of int values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
rangeClosed
Creates an Array of long numbers starting fromfrom, extending totoInclusive.Examples:
Array.rangeClosed(0L, 0L) // = Array(0L) Array.rangeClosed(2L, 0L) // = Array() Array.rangeClosed(-2L, 2L) // = Array(-2L, -1L, 0L, 1L, 2L)- Parameters:
from- the first numbertoInclusive- the last number- Returns:
- a range of long values as specified or the empty range if
from > toInclusive
-
rangeClosedBy
Creates an Array of long numbers starting fromfrom, extending totoInclusive, withstep.Examples:
Array.rangeClosedBy(1L, 3L, 1L) // = Array(1L, 2L, 3L) Array.rangeClosedBy(1L, 4L, 2L) // = Array(1L, 3L) Array.rangeClosedBy(4L, 1L, -2L) // = Array(4L, 2L) Array.rangeClosedBy(4L, 1L, 2L) // = Array()- Parameters:
from- the first numbertoInclusive- the last numberstep- the step- Returns:
- a range of int values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
IllegalArgumentException- ifstepis zero
-
unfoldRight
public static <T,U> Array<U> unfoldRight(T seed, Function<? super T, Option<Tuple2<? extends U, ? extends T>>> f) Creates an Array from a seed value and a function. The function takes the seed at first. The function should returnNonewhen it's done generating the Array, otherwiseSomeTupleof the element for the next call and the value to add to the resulting Array.Example:
Array.unfoldRight(10, x -> x == 0 ? Option.none() : Option.of(new Tuple2<gt;(x, x-1))); // Array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1))- Type Parameters:
T- type of seedsU- type of unfolded values- Parameters:
seed- the start value for the iterationf- the function to get the next step of the iteration- Returns:
- an Array with the values built up by the iteration
- Throws:
NullPointerException- iffis null
-
unfoldLeft
public static <T,U> Array<U> unfoldLeft(T seed, Function<? super T, Option<Tuple2<? extends T, ? extends U>>> f) Creates an Array from a seed value and a function. The function takes the seed at first. The function should returnNonewhen it's done generating the list, otherwiseSomeTupleof the value to add to the resulting list and the element for the next call.Example:
Array.unfoldLeft(10, x -> x == 0 ? Option.none() : Option.of(new Tuple2<gt;(x-1, x))); // Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))- Type Parameters:
T- type of seedsU- type of unfolded values- Parameters:
seed- the start value for the iterationf- the function to get the next step of the iteration- Returns:
- an Array with the values built up by the iteration
- Throws:
NullPointerException- iffis null
-
unfold
public static <T> Array<T> unfold(T seed, Function<? super T, Option<Tuple2<? extends T, ? extends T>>> f) Creates an Array from a seed value and a function. The function takes the seed at first. The function should returnNonewhen it's done generating the list, otherwiseSomeTupleof the value to add to the resulting list and the element for the next call.Example:
Array.unfold(10, x -> x == 0 ? Option.none() : Option.of(new Tuple2<gt;(x-1, x))); // Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))- Type Parameters:
T- type of seeds and unfolded values- Parameters:
seed- the start value for the iterationf- the function to get the next step of the iteration- Returns:
- an Array with the values built up by the iteration
- Throws:
NullPointerException- iffis null
-
append
Description copied from interface:SeqReturns a new sequence with the given element appended at the end. -
appendAll
Description copied from interface:SeqReturns a new sequence with all elements from the givenIterableappended at the end of this sequence. -
asJava
Description copied from interface:SeqReturns 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. -
asJava
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. -
asJavaMutable
Description copied from interface:SeqReturns a mutableListview of thisSeq. All standard mutator methods of theListinterface are supported and modify the underlying view.Unlike
Seq.asJava(), this view allows modifications, but the performance characteristics correspond to the underlying persistent Vavr collection.- Specified by:
asJavaMutablein interfaceSeq<T>- Returns:
- a mutable
Listview of this sequence - See Also:
-
asJavaMutable
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 interfaceIndexedSeq<T>- 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:
-
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 interfaceIndexedSeq<T>- 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
-
hasDefiniteSize
public boolean hasDefiniteSize()Description copied from interface:TraversableIndicates whether thisTraversablehas a known finite size.This should typically be implemented by concrete classes, not interfaces.
- Specified by:
hasDefiniteSizein interfaceTraversable<T>- Returns:
trueif the number of elements is finite and known,falseotherwise.
-
isAsync
public boolean isAsync()AnArrayis computed synchronously. -
isLazy
public boolean isLazy()AnArrayis computed eagerly. -
isTraversableAgain
public boolean isTraversableAgain()Description copied from interface:TraversableChecks if this Traversable can be traversed multiple times without side effects.Implementations should provide the correct behavior; this is not meant for interfaces alone.
- Specified by:
isTraversableAgainin interfaceTraversable<T>- Returns:
trueif this Traversable is guaranteed to be repeatably traversable,falseotherwise
-
iterator
Description copied from interface:TraversableReturns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail(). Subclasses may override for a more efficient implementation. -
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 interfaceIndexedSeq<T>- Specified by:
combinationsin interfaceSeq<T>- Returns:
- a sequence of sequences representing all combinations of this sequence's elements
-
combinations
Description copied from interface:SeqReturns all subsets of this sequence containing exactlykdistinct elements, i.e., the k-combinations of this sequence.- Specified by:
combinationsin interfaceIndexedSeq<T>- Specified by:
combinationsin interfaceSeq<T>- Parameters:
k- the size of each subset- Returns:
- a sequence of sequences representing all k-element combinations
- See Also:
-
crossProduct
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 interfaceIndexedSeq<T>- Specified by:
crossProductin interfaceSeq<T>- Parameters:
power- the number of Cartesian multiplications- Returns:
- an
Iteratorover sequences representing the Cartesian power of this sequence
-
get
Description copied from interface:SeqReturns the element at the specified index. -
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 interfaceIndexedSeq<T>- Specified by:
distinctin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- 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
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 interfaceIndexedSeq<T>- 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
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 interfaceIndexedSeq<T>- 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
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 interfaceIndexedSeq<T>- 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
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.- Specified by:
dropin interfaceIndexedSeq<T>- Specified by:
dropin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
dropUntilin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
dropWhilein interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
dropRightin interfaceSeq<T>- 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
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 interfaceIndexedSeq<T>- 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
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 interfaceIndexedSeq<T>- 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
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.- Specified by:
filterin interfaceIndexedSeq<T>- Specified by:
filterin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
rejectin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- 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
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceIndexedSeq<T>- 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:
-
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 interfaceIndexedSeq<T>- Specified by:
groupedin interfaceSeq<T>- Specified by:
groupedin interfaceTraversable<T>- Parameters:
size- the block size; must be positive- Returns:
- an
Iteratorover blocks of elements
- If empty, the resulting
-
head
Description copied from interface:TraversableReturns the first element of this non-emptyTraversable.- Specified by:
headin interfaceTraversable<T>- Returns:
- the first element
-
indexOf
Description copied from interface:SeqReturns the index of the first occurrence of the given element, starting at the specified index, or-1if this sequence does not contain the element. -
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 interfaceIndexedSeq<T>- Specified by:
initin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
initOptionin interfaceSeq<T>- Specified by:
initOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, orNoneif this Traversable is empty
-
isEmpty
public boolean isEmpty()Description copied from interface:TraversableChecks if this Traversable contains no elements. -
insert
Description copied from interface:SeqReturns a new sequence with the given element inserted at the specified index. -
insertAll
Description copied from interface:SeqReturns a new sequence with the given elements inserted at the specified index. -
intersperse
Description copied from interface:SeqReturns a new sequence where the given element is inserted between all elements of this sequence.- Specified by:
interspersein interfaceIndexedSeq<T>- Specified by:
interspersein interfaceSeq<T>- Parameters:
element- the element to intersperse- Returns:
- a new
Seqwith the element interspersed
-
lastIndexOf
Description copied from interface:SeqReturns 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.- Specified by:
lastIndexOfin interfaceSeq<T>- 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
-
length
public int length()Description copied from interface:TraversableReturns the number of elements in this Traversable.Equivalent to
Traversable.size().- Specified by:
lengthin interfaceTraversable<T>- Returns:
- the number of elements
-
map
Description copied from interface:TraversableTransforms the elements of this Traversable to a new type, preserving order if defined.- Specified by:
mapin interfaceIndexedSeq<T>- Specified by:
mapin interfaceSeq<T>- Specified by:
mapin interfaceTraversable<T>- Specified by:
mapin interfaceValue<T>- Type Parameters:
U- the target element type- Parameters:
mapper- a mapping function- Returns:
- a new Traversable containing the mapped elements
-
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 interfaceIndexedSeq<T>- Specified by:
orElsein interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
orElsein interfaceSeq<T>- 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()
-
padTo
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.
- Specified by:
padToin interfaceIndexedSeq<T>- Specified by:
padToin interfaceSeq<T>- 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
Description copied from interface:SeqReturns 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.
-
patch
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.- Specified by:
patchin interfaceIndexedSeq<T>- Specified by:
patchin interfaceSeq<T>- 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
-
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 interfaceIndexedSeq<T>- Specified by:
partitionin interfaceSeq<T>- 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. -
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 interfaceIndexedSeq<T>- Specified by:
permutationsin interfaceSeq<T>- Returns:
- a sequence of all unique permutations of this sequence
-
prepend
Description copied from interface:SeqReturns a new sequence with the given element prepended to this sequence. -
prependAll
Description copied from interface:SeqReturns a new sequence with all given elements prepended to this sequence.- Specified by:
prependAllin interfaceIndexedSeq<T>- 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
Description copied from interface:SeqReturns a new sequence with the first occurrence of the given element removed. -
removeFirst
Description copied from interface:SeqReturns a new sequence with the first element that satisfies the given predicate removed.- Specified by:
removeFirstin interfaceIndexedSeq<T>- 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
Description copied from interface:SeqReturns a new sequence with the last element that satisfies the given predicate removed.- Specified by:
removeLastin interfaceIndexedSeq<T>- 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
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
Description copied from interface:SeqReturns a new sequence with all occurrences of the given element removed. -
removeAll
Description copied from interface:SeqReturns a new sequence with all occurrences of the given elements removed. -
removeAll
Deprecated.Description copied from interface:SeqReturns a new Seq consisting of all elements which do not satisfy the given predicate. -
replace
Description copied from interface:TraversableReplaces the first occurrence ofcurrentElementwithnewElement, if it exists.- Specified by:
replacein interfaceIndexedSeq<T>- Specified by:
replacein interfaceSeq<T>- 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 interfaceIndexedSeq<T>- 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
Description copied from interface:TraversableRetains only the elements from this Traversable that are contained in the givenelements.- Specified by:
retainAllin interfaceIndexedSeq<T>- Specified by:
retainAllin interfaceSeq<T>- 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
-
reverse
Description copied from interface:SeqReturns a new sequence with the order of elements reversed. -
rotateLeft
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 interfaceIndexedSeq<T>- Specified by:
rotateLeftin interfaceSeq<T>- Parameters:
n- the number of positions to rotate left- Returns:
- a new
Seqwith elements rotated left
-
rotateRight
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 interfaceIndexedSeq<T>- Specified by:
rotateRightin interfaceSeq<T>- Parameters:
n- the number of positions to rotate right- Returns:
- a new
Seqwith elements rotated right
-
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 interfaceIndexedSeq<T>- Specified by:
scanin interfaceSeq<T>- 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
public <U> Array<U> scanLeft(U zero, @NonNull 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 interfaceIndexedSeq<T>- 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
public <U> Array<U> scanRight(U zero, @NonNull 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 interfaceIndexedSeq<T>- 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
-
shuffle
Description copied from interface:SeqReturns a new sequence with the elements randomly shuffled. -
slice
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
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 interfaceIndexedSeq<T>- Specified by:
slideByin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
slidingin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
slidingin interfaceSeq<T>- 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
-
sorted
Description copied from interface:SeqReturns a new sequence with elements sorted according to their natural order. -
sorted
Description copied from interface:SeqReturns a new sequence with elements sorted according to the givenComparator. -
sortBy
public <U extends Comparable<? super U>> Array<T> sortBy(@NonNull 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.- Specified by:
sortByin interfaceIndexedSeq<T>- Specified by:
sortByin interfaceSeq<T>- 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
-
sortBy
public <U> Array<T> sortBy(@NonNull Comparator<? super U> comparator, 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 interfaceIndexedSeq<T>- 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
-
splitAt
Description copied from interface:SeqSplits this sequence at the specified index.The result of
splitAt(n)is equivalent toTuple.of(take(n), drop(n)). -
splitAt
Description copied from interface:SeqSplits this sequence at the first element satisfying the given predicate. -
splitAtInclusive
Description copied from interface:SeqSplits this sequence at the first element satisfying the given predicate, including the element in the first part.- Specified by:
splitAtInclusivein interfaceSeq<T>- 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
-
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 interfaceIndexedSeq<T>- Specified by:
spanin interfaceSeq<T>- Specified by:
spanin interfaceTraversable<T>- Parameters:
predicate- a predicate used to determine the prefix- Returns:
- a
Tuplecontaining the prefix and remainder
-
subSequence
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 interfaceIndexedSeq<T>- Specified by:
subSequencein interfaceSeq<T>- Parameters:
beginIndex- the starting index (inclusive) of the subsequence- Returns:
- a new
Seqrepresenting the subsequence frombeginIndexto the end
-
subSequence
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 interfaceIndexedSeq<T>- 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
Description copied from interface:TraversableReturns a newTraversablewithout its first element.- Specified by:
tailin interfaceIndexedSeq<T>- Specified by:
tailin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
tailOptionin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
takein interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
takeUntilin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
takeWhilein interfaceSeq<T>- 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 interfaceIndexedSeq<T>- Specified by:
takeRightin interfaceSeq<T>- Specified by:
takeRightin interfaceTraversable<T>- Parameters:
n- the number of elements to take from the end- Returns:
- a new
Traversablecontaining the lastnelements
-
takeRightUntil
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 interfaceIndexedSeq<T>- 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
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 interfaceIndexedSeq<T>- 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
-
transform
Transforms thisArray.- Type Parameters:
U- Type of transformation result- Parameters:
f- A transformation- Returns:
- An instance of type
U - Throws:
NullPointerException- iffis null
-
unzip
public <T1,T2> Tuple2<Array<T1>,Array<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 interfaceIndexedSeq<T>- 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
-
unzip3
public <T1,T2, Tuple3<Array<T1>,T3> Array<T2>, unzip3Array<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 interfaceIndexedSeq<T>- Specified by:
unzip3in interfaceSeq<T>- 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
-
update
Description copied from interface:SeqReturns a newSeqwith the element at the specified index replaced by the given value. -
update
Description copied from interface:SeqReturns a newSeqwith the element at the specified index updated using the given function. -
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 interfaceIndexedSeq<T>- 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
public <U,R> Array<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 interfaceIndexedSeq<T>- 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
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 interfaceIndexedSeq<T>- 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
Description copied from interface:TraversableZips thisTraversablewith its indices, starting at 0.- Specified by:
zipWithIndexin interfaceIndexedSeq<T>- Specified by:
zipWithIndexin interfaceSeq<T>- 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 interfaceIndexedSeq<T>- 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
-
equals
Description copied from interface:TraversableDetermines whether this collection is equal to the given object.In Vavr, there are four basic collection types:
Seq– sequential elementsSet– distinct elementsMap– key-value pairsMultimap– keys mapped to multiple values
- They are of the same collection type (Seq, Set, Map, Multimap)
- They contain the same elements
- For
Seq, the element order is the same
For
MapandMultimap, two entries(key1, value1)and(key2, value2)are equal if both their keys and values are equal.Additional notes:
- No collection equals
null(e.g.,Queue(1) != null) - Null elements are allowed and treated as expected
(e.g.,
List(null, 1) == Stream(null, 1),HashMap((null,1)) == LinkedHashMap((null,1))) - Element order matters only for
Seq - Other collection classes are equal if their types and elements (in iteration order) are equal
- Iterators are compared by reference only
-
hashCode
public int hashCode()Description copied from interface:TraversableReturns the hash code of this collection.Vavr distinguishes between collections with predictable iteration order (like
Seq) and collections with arbitrary iteration order (likeSet,Map, andMultimap). In all cases, the hash of an empty collection is defined as1.For collections with predictable iteration order, the hash is computed as:
int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }For collections with arbitrary iteration order, the hash is computed to be independent of element order:
int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as
HashMapkeys), caching can be done externally using a wrapper, for example:public final class Hashed<K> { private final K key; private final Lazy<Integer> hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; } @Override public boolean equals(Object o) { if (o == key) return true; if (key != null && o instanceof Hashed) return key.equals(((Hashed<?>) o).key); return false; } @Override public int hashCode() { return hashCode.get(); } @Override public String toString() { return "Hashed(" + key + ")"; } } -
stringPrefix
Description copied from interface:ValueReturns the name of this Value type, which is used by toString().- Specified by:
stringPrefixin interfaceValue<T>- Returns:
- This type name.
-
toString
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-