IVector<A> class sealed

An immutable, indexed sequence backed by a Radix-Balanced Finger Tree.

Provides effectively O(1) indexed access, update, append, and prepend for collections of any practical size (up to 2^31 elements). The internal representation scales automatically across six tree depths as the vector grows.

Construct with ivec, IVector.fromDart, IVector.from, IVector.fill, IVector.tabulate, or IVector.empty. Use IVector.builder when building incrementally.

final v = ivec([1, 2, 3]);
final v2 = v.appended(4);     // IVector(1, 2, 3, 4)
final v3 = v2.prepended(0);   // IVector(0, 1, 2, 3, 4)
v3[2];                         // 2
v3.updated(2, 99);             // IVector(0, 1, 99, 3, 4)
Mixed-in types
Available extensions

Properties

hashCode int
The hash code for this object.
no setteroverride
Returns the first element of this collection, or throws if it is empty.
no setterinherited
headOption Option<A>
Returns the first element of this collection as a Some if non-empty. If this collction is empty, None is returned.
no setterinherited
init IVector<A>
Returns all elements from this collection except the last. If this collection is empty, an empty collection is returned.
no setteroverride
inits RIterator<IVector<A>>
Returns an iterator of all potential tails of this collection, starting with the entire collection and ending with an empty one.
no setteroverride
isEmpty bool
Whether this collection contains no elements.
no setterinherited
isNotEmpty bool
Whether this collection contains at least one element.
no setterinherited
isTraversableAgain bool
Whether this collection can be traversed more than once.
no setterinherited
iterator RIterator<A>
Returns an RIterator over the elements of this collection.
no setteroverride
knownSize int
Returns the number of elements in this collection, if that number is already known. If not, -1 is returned.
no setteroverride
last → A
Returns the last element of this collection, or throws if it is empty.
no setterinherited
lastOption Option<A>
Returns the last element of this collection as a Some, or None if this collection is empty.
no setterinherited
length int
The number of elements in this sequence.
no setteroverride
nonEmpty bool
Whether this collection contains at least one element.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
size int
Returns the number of elements in this collection.
no setterinherited
tail IVector<A>
Returns a new collection with the first element removed. If this collection is empty, an empty collection is returned.
no setteroverride
tails RIterator<IVector<A>>
Returns an iterator of all potential tails of this collection, starting with the entire collection and ending with an empty one.
no setteroverride

Methods

appended(A elem) IVector<A>
Returns a new vector with elem added at the end.
override
appendedAll(RIterableOnce<A> suffix) IVector<A>
Returns a new Seq, with elems added to the end.
override
canEqual(Object other) bool
inherited
collect<B>(Function1<A, Option<B>> f) IVector<B>
Returns a new collection by applying f to each element an only keeping results of type Some.
override
collectFirst<B>(Function1<A, Option<B>> f) Option<B>
Applies f to each element of this collection, returning the first element that results in a Some, if any.
inherited
combinations(int n) RIterator<IVector<A>>
Returns an Iterator that will produce all combinations of elements from this sequence of size n in order.
override
concat(covariant RIterableOnce<A> suffix) IVector<A>
Returns a copy of this collection, with elems added to the end.
override
contains(A elem) bool
Returns true, if any element of this collection equals elem.
inherited
containsSlice(RSeq<A> that) bool
Returns true if that is contained in this collection, in order.
inherited
copyToArray(Array<A> xs, [int start = 0, int? n]) int
Copies elements into xs starting at start, writing at most n elements (or all remaining capacity when n is omitted).
inherited
corresponds<B>(covariant RIterable<B> that, Function2<A, B, bool> p) bool
Returns true if this collection has the same size as that and each corresponding element from this and that satisfies the given predicate p.
inherited
count(Function1<A, bool> p) int
Return the number of elements in this collection that satisfy the given predicate.
inherited
diff(RSeq<A> that) IVector<A>
Returns a new collection with the difference of this and that, i.e. all elements that appear in only this collection.
override
distinct() IVector<A>
Returns a new collection where every element is distinct according to equality.
override
distinctBy<B>(Function1<A, B> f) IVector<A>
Returns a new collection where every element is distinct according to the application of f to each element.
override
drop(int n) IVector<A>
Returns a new collection with the first n elements removed.
override
dropRight(int n) IVector<A>
Return a new collection with the last n elements removed.
override
dropWhile(Function1<A, bool> p) IVector<A>
Returns a new collection with leading elements satisfying p removed.
override
endsWith(RIterable<A> that) bool
Returns true if the end of this collection has the same elements in order as that. Otherwise, false is returned.
inherited
exists(Function1<A, bool> p) bool
Returns true if any element of this collection satisfies the given predicate, false if no elements satisfy it.
inherited
filter(Function1<A, bool> p) IVector<A>
Returns a new collection containing only elements that satisfy p.
override
filterNot(Function1<A, bool> p) IVector<A>
Returns a new collection containing only elements that do not satisfy p.
override
find(Function1<A, bool> p) Option<A>
Returns the first element from this collection that satisfies the given predicate p. If no element satisfies p, None is returned.
inherited
findLast(Function1<A, bool> p) Option<A>
Returns the last element satisfying p as Some, or None if none.
inherited
flatMap<B>(covariant Function1<A, RIterableOnce<B>> f) IVector<B>
Returns a new collection by applying f to each element and concatenating the results.
override
flatten() RIterable<A>

Available on RIterable<RIterable<A>>, provided by the RIterableNested2Ops extension

Concatenates all inner iterables into a single IList.
fold(A init, Function2<A, A, A> op) → A
Alias for foldLeft with a same-type accumulator.
inherited
foldLeft<B>(B z, Function2<B, A, B> op) → B
Returns a summary value by applying op to all elements of this collection, moving from left to right. The fold uses a seed value of z.
inherited
foldRight<B>(B z, Function2<A, B, B> op) → B
Returns a summary value by applying op to all elements of this collection, moving from right to left. The fold uses a seed value of z.
inherited
forall(Function1<A, bool> p) bool
Returns true if all elements of this collection satisfy the given predicate, false if any elements do not.
inherited
foreach<U>(Function1<A, U> f) → void
Applies f to each element of this collection, discarding any resulting values.
inherited
groupBy<K>(Function1<A, K> f) IMap<K, IVector<A>>
Partitions all elements of this collection by applying f to each element and accumulating duplicate keys in the returned IMap.
override
grouped(int size) RIterator<IVector<A>>
Returns a new iterator where each element is a collection of size elements from the original collection. The last element may contain less than size elements.
override
groupMap<K, B>(Function1<A, K> key, Function1<A, B> f) IMap<K, IVector<B>>
Creates a new map by generating a key-value pair for each elements of this collection using key and f. Any elements that generate the same key will have the resulting values accumulated in the returned map.
override
groupMapReduce<K, B>(Function1<A, K> key, Function1<A, B> f, Function2<B, B, B> reduce) IMap<K, B>
Partitions all elements of this collection by applying key to each element. Additionally f is applied to each element to generate a value. If multiple values are generating for the same key, those values will be combined using reduce.
inherited
indexOf(A elem, [int from = 0]) Option<int>
Returns the first index, if any, where the element at that index equals elem. If no index contains elem, None is returned.
inherited
indexOfSlice(RSeq<A> that, [int from = 0]) Option<int>
Finds the first index in this collection where the next sequence of elements is equal to that. If that cannot be found in this collection, None is returned.
inherited
indexWhere(Function1<A, bool> p, [int from = 0]) Option<int>
Returns the index of the first element that satisfies the predicate p. If no element satisfies, None is returned.
inherited
indices() Range
Returns a range of all indices of this sequence
inherited
intersect(RSeq<A> that) IVector<A>
Returns a new collection with the intersection of this and that, i.e. all elements that appear in both collections.
override
intersperse(A x) IVector<A>
Returns a new collection with sep inserted between each element.
override
isDefinedAt(int idx) bool
Returns true if this collection has an element at the given idx.
inherited
lastIndexOf(A elem, [int end = 2147483647]) Option<int>
Returns the last index, if any, where the element at that index equals elem. If no index contains elem, None is returned.
inherited
lastIndexOfSlice(RSeq<A> that, [int end = 2147483647]) Option<int>
Finds the last index in this collection where the next sequence of elements is equal to that. If that cannot be found in this collection, None is returned.
inherited
lastIndexWhere(Function1<A, bool> p, [int end = 2147483647]) Option<int>
Returns the index of the last element that satisfies the predicate p. If no element satisfies, None is returned.
inherited
lift(int ix) Option<A>
Returns the element at index ix as a Some. If ix is outside the range of this collection, None is returned.
inherited
map<B>(Function1<A, B> f) IVector<B>
Returns a new vector produced by applying f to each element.
override
maxByOption<B>(Function1<A, B> f, Order<B> order) Option<A>
Finds the largest element in this collection by applying f to each element and using the given Order to find the greatest.
inherited
maxOption(Order<A> order) Option<A>
Finds the largest element in this collection according to the given Order.
inherited
minByOption<B>(Function1<A, B> f, Order<B> order) Option<A>
Finds the smallest element in this collection by applying f to each element and using the given Order to find the greatest.
inherited
minOption(Order<A> order) Option<A>
Finds the largest element in this collection according to the given Order.
inherited
mkString({String? start, String? sep, String? end}) String
Returns a String by using each elements toString(), adding sep between each element. If start is defined, it will be prepended to the resulting string. If end is defined, it will be appended to the resulting string.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
padTo(int len, A elem) IVector<A>
Returns a new collection with a length of at least len.
override
partition(Function1<A, bool> p) → (IVector<A>, IVector<A>)
Returns 2 collections as a tuple where the first tuple element will be a collection of elements that satisfy the given predicate p. The second item of the returned tuple will be elements that do not satisfy p.
override
partitionMap<A1, A2>(Function1<A, Either<A1, A2>> f) → (IVector<A1>, IVector<A2>)
Applies f to each element of this collection and returns a separate collection for all applications resulting in a Left and Right respectively.
override
patch(int from, RIterableOnce<A> other, int replaced) IVector<A>
Returns a new collection with replaced elements starting at from replaced by the elements of other.
override
permutations() RIterator<IVector<A>>
Returns an Iterator that will emit all possible permutations of the elements in this collection.
override
prepended(A elem) IVector<A>
Returns a new vector with elem added at the front.
override
prependedAll(RIterableOnce<A> prefix) IVector<A>
Returns a new collection with all elems added to the beginning.
override
product() int

Available on RIterableOnce<int>, provided by the RIterableIntOps extension

Returns the product of all elements in this list
product() double

Available on RIterableOnce<double>, provided by the RIterableDoubleOps extension

Returns the product of all elements in this list
reduce(Function2<A, A, A> op) → A
Reduces this collection to a single value by applying op left to right.
inherited
reduceLeft(Function2<A, A, A> op) → A
Reduces from left to right. Throws if empty.
inherited
reduceLeftOption(Function2<A, A, A> op) Option<A>
Returns a summary values of all elements of this collection by applying f to each element, moving left to right.
inherited
reduceOption(Function2<A, A, A> op) Option<A>
Returns a summary values of all elements of this collection by applying f to each element, moving left to right.
inherited
reduceRight(Function2<A, A, A> op) → A
Reduces from right to left. Throws if empty.
inherited
reduceRightOption(Function2<A, A, A> op) Option<A>
Returns a summary values of all elements of this collection by applying f to each element, moving right to left.
inherited
removeAt(int idx) IVector<A>
Returns a new collection with the element at idx removed.
override
removeFirst(Function1<A, bool> p) IVector<A>
Returns a new vector with the first element satisfying p removed.
reverse() IVector<A>
Returns a new collection with the order of the elements reversed.
override
reverseIterator() RIterator<A>
Returns an iterator that will emit all elements in this collection, in reverse order.
inherited
sameElements(RIterable<A> that) bool
Returns true if this collection has the same elements, in the same order, as that.
inherited
scan<B>(B z, Function2<B, A, B> op) IVector<B>
Alias for scanLeft.
override
scanLeft<B>(B z, Function2<B, A, B> op) IVector<B>
Returns a new collection of running totals starting with z.
override
scanRight<B>(B z, Function2<A, B, B> op) IVector<B>
Returns a new collection of running totals starting with z, traversing from right to left.
override
segmentLength(Function1<A, bool> p, [int from = 0]) int
Returns the length of the longest prefix starting at from where every element satisfies p.
inherited
slice(int from, int until) IVector<A>
Returns a vector containing the elements from index from (inclusive) to until (exclusive). Out-of-bound indices are clamped silently.
override
sliding(int size, [int step = 1]) RIterator<IVector<A>>
Returns an iterator where elements are fixed size chunks of size n of the original collection. Each chunk is calculated by sliding a 'window' of size n over the original collection, moving the window step elements at a time.
override
sortBy<B>(Order<B> order, Function1<A, B> f) IVector<A>
Returns a new collection that is sorted according to order after applying f to each element in this collection.
override
sorted(Order<A> order) IVector<A>
Returns a new collection that is sorted according to order.
override
sortWith(Function2<A, A, bool> lt) IVector<A>
Returns a new collection sorted using the provided function lt which is used to determine if one element is less than the other.
override
span(Function1<A, bool> p) → (IVector<A>, IVector<A>)
Returns two collections: elements before and starting from the first element that does not satisfy p.
override
splitAt(int n) → (IVector<A>, IVector<A>)
Returns two collections: the first n elements and the remainder.
override
startsWith(RIterableOnce<A> that, [int offset = 0]) bool
Returns true if the beginning of this collection corresponds with that.
inherited
sum() int

Available on RIterableOnce<int>, provided by the RIterableIntOps extension

Returns the sum of all elements in this list
sum() double

Available on RIterableOnce<double>, provided by the RIterableDoubleOps extension

Returns the sum of all elements in this list
take(int n) IVector<A>
Returns a new collection containing only the first n elements.
override
takeRight(int n) IVector<A>
Returns a new collection with the last n elements of this collection. If n is greater than the size of this collection, the original collection is returned.
override
takeWhile(Function1<A, bool> p) IVector<A>
Returns a new collection of leading elements that satisfy p.
override
tapEach<U>(Function1<A, U> f) RIterable<A>
Applies f to each element in this collection, discarding any results and returns this collection.
override
toIList() IList<A>
Returns an IList with the same elements as this collection.
inherited
toIMap() IMap<A, B>

Available on RIterable<(A, B)>, provided by the RIterableTuple2Ops extension

Creates a new IMap where each tuple element of this list is used to create a key and value respectively.
toIndexedSeq() IndexedSeq<A>
Returns an IndexedSeq with the same elements as this collection.
inherited
toISet() ISet<A>
Returns an ISet with the same elements as this collection, duplicates removed.
inherited
toIVector() IVector<A>
Returns an IVector with the same elements as this collection.
inherited
toList({bool growable = true}) List<A>
Returns a new List with the same elements as this collection.
inherited
toSeq() RSeq<A>
Returns a RSeq with the same elements as this collection.
inherited
toString() String
A string representation of this object.
override
traverseEither<B, C>(Function1<A, Either<B, C>> f) Either<B, IVector<C>>
Applies f to each element of this RSeq and collects the results into a new collection. If Left is encountered for any element, that result is returned and any additional elements will not be evaluated.
override
traverseOption<B>(Function1<A, Option<B>> f) Option<IVector<B>>
Applies f to each element of this RSeq and collects the results into a new collection. If None is encountered for any element, that result is returned and any additional elements will not be evaluated.
override
unzip() → (IndexedSeq<A>, IndexedSeq<B>)

Available on IndexedSeq<(A, B)>, provided by the IndexedSeqTuple2Ops extension

unzip() → (RIterable<A>, RIterable<B>)

Available on RIterable<(A, B)>, provided by the RibsIterableTuple2Ops extension

Splits a collection of pairs into two separate collections.
updated(int index, A elem) IVector<A>
Returns a new vector with the element at index replaced by elem.
override
zip<B>(RIterableOnce<B> that) IVector<(A, B)>
Returns a new collection that combines corresponding elements from this collection and that as a tuple. The length of the returned collection will be the minimum of this collections size and the size of that.
override
zipAll<B>(RIterableOnce<B> that, A thisElem, B thatElem) IVector<(A, B)>
Returns a new collection that combines corresponding elements from this collection and that as a tuple. The length of the returned collection will be the maximum of this collections size and thes size of that. If this collection is shorter than that, thisElem will be used to fill in the resulting collection. If that is shorter, thatElem will be used to will in the resulting collection.
override
zipWithIndex() IVector<(A, int)>
Return a new collection with each element of this collection paired with it's respective index.
override

Operators

operator ==(Object other) bool
The equality operator.
override
operator [](int idx) → A
Returns the element at index idx.
inherited

Static Methods

builder<A>() IVectorBuilder<A>
Returns a mutable builder that accumulates elements into an IVector.
empty<A>() IVector<A>
Returns an empty IVector.
override
fill<A>(int n, A elem) IVector<A>
Creates an IVector of length n with every element set to elem.
fill2<A>(int n1, int n2, A elem) IVector<IVector<A>>
Creates a 2-dimensional IVector of shape n1 × n2, filled with elem.
fill3<A>(int n1, int n2, int n3, A elem) IVector<IVector<IVector<A>>>
Creates a 3-dimensional IVector of shape n1 × n2 × n3, filled with elem.
fill4<A>(int n1, int n2, int n3, int n4, A elem) IVector<IVector<IVector<IVector<A>>>>
Creates a 4-dimensional IVector of shape n1 × n2 × n3 × n4, filled with elem.
fill5<A>(int n1, int n2, int n3, int n4, int n5, A elem) IVector<IVector<IVector<IVector<IVector<A>>>>>
Creates a 5-dimensional IVector of shape n1 × n2 × n3 × n4 × n5, filled with elem.
from<A>(RIterableOnce<A> elems) IVector<A>
Creates an IVector from any RIterableOnce.
override
fromDart<A>(Iterable<A> elems) IVector<A>
Creates an IVector from a Dart Iterable.
override
tabulate<A>(int n, Function1<int, A> f) IVector<A>
Creates an IVector of length n where each element at index i is computed by applying f to i.
tabulate2<A>(int n1, int n2, Function2<int, int, A> f) IVector<IVector<A>>
Creates a 2-dimensional IVector of shape n1 × n2 using f to compute element (i1, i2).
tabulate3<A>(int n1, int n2, int n3, Function3<int, int, int, A> f) IVector<IVector<IVector<A>>>
Creates a 3-dimensional IVector of shape n1 × n2 × n3 using f to compute element (i1, i2, i3).
tabulate4<A>(int n1, int n2, int n3, int n4, Function4<int, int, int, int, A> f) IVector<IVector<IVector<IVector<A>>>>
Creates a 4-dimensional IVector of shape n1 × n2 × n3 × n4 using f to compute element (i1, i2, i3, i4).
tabulate5<A>(int n1, int n2, int n3, int n4, int n5, Function5<int, int, int, int, int, A> f) IVector<IVector<IVector<IVector<IVector<A>>>>>
Creates a 5-dimensional IVector of shape n1 × n2 × n3 × n4 × n5 using f to compute element (i1, i2, i3, i4, i5).