Slice<T> class final

A contiguous sequence of elements in a List. Slices are a view into a list without allocating and copying to a new list, as such, they do not own their own data. Note: Shrinking the original list can cause the slices range to become invalid, which may cause an exception.

Implemented types
Available extensions

Constructors

Slice(List<T> _list, int _start, int _end)
Slice.fromList(List<T> list)
Slice.fromSlice(Slice<T> slice, [int start = 0, int end = -1])

Properties

first → T
The first element.
no setteroverride
firstOrOption Option<T>
no setter
hashCode int
The hash code for this object.
no setteroverride
isEmpty bool
Whether this collection has no elements.
no setteroverride
isNotEmpty bool
Whether this collection has at least one element.
no setteroverride
iterator Iterator<T>
A new Iterator that allows iterating the elements of this Iterable.
no setteroverride
last → T
Returns the last element of the slice, can throw.
no setteroverride
lastOrOption Option<T>
Returns the last element of the slice, or None if it is empty.
no setter
length int
The number of elements in this Iterable.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single → T
Checks that this iterable has only one element, and returns that element.
no setteroverride

Methods

any(bool f(T)) bool
Checks whether any element of this iterable satisfies test.
override
cast<U>() RIterator<U>
A view of this iterable as an iterable of R instances.
override
contains(Object? element) bool
Whether the collection contains an element equal to element.
override
copyFromSlice(Slice<T> src) → void
Copies the elements from src into self. The length of src must be the same as self.
elementAt(int index) → T
Returns the indexth element.
override
endsWith(Slice<T> needle) bool
Returns true if needle is a suffix of the slice.
every(bool f(T)) bool
Checks whether every element of this iterable satisfies test.
override
expand<U>(Iterable<U> f(T)) RIterator<U>
Expands each element of this Iterable into zero or more elements.
override
fill(T value) → void
Fills this slice with value.
fillWith(T f()) → void
Fills this slice with the value return by calling f repeatedly.
firstWhere(bool f(T), {T orElse()?}) → T
The first element that satisfies the given predicate test.
override
fold<U>(U initialValue, U f(U previousValue, T element)) → U
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
override
followedBy(Iterable<T> other) RIterator<T>
Creates the lazy concatenation of this iterable and other.
override
forEach(void f(T)) → void
Invokes action on each element of this iterable in iteration order.
override
get(int index) Option<T>
getMany(List<int> indices) Result<Arr<T>, GetManyError>
Returns mutable references to many indices at once. Returns an error if any index is out-of-bounds.
getManyUnchecked(List<int> indices) Arr<T>
Returns mutable references to many indices at once, without doing any checks.
getUnchecked(int index) → dynamic
Returns the element at the given index without doing bounds checking.
groupBy(bool compare(T, T)) RIterator<Slice<T>>
Returns an %iterator over the slice producing non-overlapping runs of elements using the predicate to separate them.
isSortedBy(Comparator<T> compare) bool
Checks if the elements of this slice are sorted using the given comparator function.
isSortedByKey<K extends Comparable<K>>(K key(T)) bool
Checks if the elements of this slice are sorted using the given key extraction function.
iter() RIterator<T>
join([String separator = '']) String
Converts each element to a String and concatenates the strings.
override
lastWhere(bool f(T), {T orElse()?}) → T
The last element that satisfies the given predicate test.
override
len() int
Returns the length of the slice.
map<U>(U f(T)) RIterator<U>
The current elements of this iterable modified by toElement.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(T f(T, T)) → T
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
override
reverse() → void
Reverses the order of elements in the slice, in place.
rsplit(bool pred(T)) RIterator<Slice<T>>
Returns an iterator over subslices separated by elements that match pred, starting at the end of the slice and working backwards. The matched element is not contained in the subslices.
rsplitAt(int index) → (Slice<T>, Slice<T>)
Divides one slice into a slice and a remainder slice at an index from the end. The slice will contain all indices from [0, len - N) (excluding the index N itself) and the second slice will contain all indices from [len - N, len) (excluding the index len itself).
rsplitOnce(bool pred(T)) Option<(Slice<T>, Slice<T>)>
Splits the slice on the last element that matches the specified predicate. If any matching elements are resent in the slice, returns the prefix before the match and suffix after. The matching element itself is not included. If no elements match, returns None.
singleWhere(bool f(T), {T orElse()?}) → T
The single element that satisfies test.
override
skip(int count) RIterator<T>
Creates an Iterable that provides all but the first count elements.
override
skipWhile(bool f(T)) RIterator<T>
Creates an Iterable that skips leading elements while test is satisfied.
override
sortUnstableBy(int compare(T a, T b)) → void
Sorts the slice with a comparator function, but might not preserve the order of equal elements.
sortUnstableByKey<K extends Comparable<K>>(K key(T a)) → void
Sorts the slice with a key extraction function, but might not preserve the order of equal elements.
split(bool pred(T)) RIterator<Slice<T>>
Returns an iterator over subslices separated by elements that match pred. The matched element is not contained in the subslices. see splitInclusive also.
splitAt(int index) → (Slice<T>, Slice<T>)
Divides one mutable slice into a slice and a remainder slice at an index. The slice will contain all indices from [0, N) (excluding the index N itself) and the second slice will contain all indices from [N, len) (excluding the index len itself).
splitFirst() Option<(T, Slice<T>)>
Returns the first and all the rest of the elements of the slice, or None if it is empty.
splitInclusive(bool pred(T)) RIterator<Slice<T>>
Returns an iterator over subslices separated by elements that match pred. The matched element is contained in the end of the previous subslice as a terminator. see split also.
splitLast() Option<(T, Slice<T>)>
Returns the last and all the rest of the elements of the slice, or None if it is empty.
splitn(int n, bool pred(T)) RIterator<Slice<T>>
Returns an iterator over subslices separated by elements that match pred, limited to returning at most n items. e.g. n == 1 will return the whole slice. The matched element is not contained in the subslices. The last element returned, if any, will contain the remainder of the slice.
splitOnce(bool pred(T)) Option<(Slice<T>, Slice<T>)>
Splits the slice on the first element that matches the specified predicate. If any matching elements are resent in the slice, returns the prefix before the match and suffix after. The matching element itself is not included. If no elements match, returns None.
startsWith(Slice<T> needle) bool
Returns true if needle is a prefix of the slice.
stripPrefix(Slice<T> prefix) Option<Slice<T>>
Returns a subslice with the prefix removed. Returns none if the prefix is not present.
stripSuffix(Slice<T> suffix) Option<Slice<T>>
swap(int i, int j) → void
Swaps two elements in the slice. Will throw if the indices are out of bounds.
swapWithSlice(Slice<T> other) → void
Swaps all elements in this with those in other. The length of other must be the same as this. Will throw if the length of other is not the same as this.
take(int count) RIterator<T>
Creates a lazy iterable of the count first elements of this iterable.
override
takeEnd(int from) Option<Slice<T>>
Returns a new slice of this slice from the end, and removes those elements from this slice. Returns None and does not modify the slice if the given range is out of bounds.
takeFirst() Option<T>
takeLast() Option<T>
takeStart(int to) Option<Slice<T>>
Returns a new slice of this slice until to, and removes those elements from this slice. Returns None and does not modify the slice if the given range is out of bounds.
takeWhile(bool f(T)) RIterator<T>
Creates a lazy iterable of the leading elements satisfying test.
override
toList({bool growable = true}) List<T>
growable is ignore, always returns a growable list.
override
toSet() Set<T>
Creates a Set containing the same elements as this iterable.
override
toString() String
A string representation of this object.
override
where(bool f(T)) RIterator<T>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
override
whereType<U>() RIterator<U>
Creates a new lazy Iterable with all elements that have type T.
override
windows(int size) RIterator<Slice<T>>

Operators

operator ==(Object other) bool
The equality operator.
override
operator [](int index) → T
operator []=(int index, T value) → void