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 or unintended behavior.
- Implemented types
-
- List<
T>
- List<
- Available extensions
- AnyhowIterableResultExtension
- Array$IterableExtension
- Array$ListExtension
- EnumByName
- FutureIterable
- Iter$IterableExtension
- Iter$IterableNullable
- Iter$IterableOption
- IterableExtensions
- ListToJSArray
- NullableIterableExtensions
- OpsListExtension
- Result$IterableFutureResultExtension
- Result$IterableResultExtension
- Slice$ListExtension
- Slice$SliceComparableSelfExtension
- Slice$SliceConcreteExtension
- Slice$SliceNumExtension
- Vec$IterableExtension
- Vec$ListExtension
- Vec$ListListExtension
- Vec$VecConcreteExtension
Constructors
-
Slice.new(List<
T> _list, [int _start = 0, int? end]) -
Slice.fromList(List<
T> list) -
Slice.fromSlice(Slice<
T> slice, [int start = 0, int? end])
Properties
- first ↔ T
-
The first element.
getter/setter pairoverride
- firstOrNull → T?
-
Available on Iterable<
The first element of this iterator, orT> , provided by the IterableExtensions extensionnull
if the iterable is empty.no setter -
firstOrOption
→ Option<
T> -
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
-
indexed
→ Iterable<
(int, T)> -
Available on Iterable<
Pairs of elements of the indices and elements of this iterable.T> , provided by the IterableExtensions extensionno setter - 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 thisIterable
.no setteroverride - last ↔ T
-
Returns the last element of the slice, can throw.
getter/setter pairoverride
- lastOrNull → T?
-
Available on Iterable<
The last element of this iterable, orT> , provided by the IterableExtensions extensionnull
if the iterable is empty.no setter -
lastOrOption
→ Option<
T> -
Returns the last element of the slice, or None if it is empty.
no setter
- length ↔ int
-
The number of objects in this list.
getter/setter pairoverride
-
nonNulls
→ Iterable<
T> -
Available on Iterable<
The non-T?> , provided by the NullableIterableExtensions extensionnull
elements of this iterable.no setter -
reversed
→ Iterable<
T> -
An Iterable of the objects in this list in reverse order.
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
- singleOrNull → T?
-
Available on Iterable<
The single element of this iterator, orT> , provided by the IterableExtensions extensionnull
.no setter -
toJS
→ JSArray<
T> -
Available on List<
Converts this List to a JSArray by either casting, unwrapping, or cloning the List.T> , provided by the ListToJSArray extensionno setter -
toJSProxyOrRef
→ JSArray<
T> -
Available on List<
Converts this List to a JSArray by either casting, unwrapping, or proxying the List.T> , provided by the ListToJSArray extensionno setter -
wait
→ Future<
List< T> > -
Available on Iterable<
Waits for futures in parallel.Future< , provided by the FutureIterable extensionT> >no setter
Methods
-
add(
T value) → void -
Adds
value
to the end of the slice, extending the length of the underlying list and this slice by one. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
addAll(
Iterable< T> iterable) → void -
Appends all objects of
iterable
to the end of this slice. Extends the length of the underlying list and this slice by the number of objects initerable
. The underlying list must be growable. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
any(
bool f(T)) → bool -
Checks whether any element of this iterable satisfies
test
.override -
append(
List< T> other) → void -
Available on List<
Adds all of other's elements to this Vec.T> , provided by the Vec$ListExtension extension -
arrayWindows(
int size) → Iter< Arr< T> > - Returns an iterator over all contiguous windows of length size. The windows overlap. If the array is shorter than size, the iterator returns no values. Panics if size is zero or less.
-
asArr(
) → Arr< T> -
Available on List<
Transmutes a List into an ArrayT> , provided by the Array$ListExtension extension -
asChunks(
int chunkSize) → (Arr< Arr< , Arr<T> >T> ) -
Splits the slice into a slice of N-element arrays, starting at the beginning of the slice,
and a remainder slice with length strictly less than N.
Panics if
chunkSize
is 0 or less. -
asMap(
) → Map< int, T> -
An unmodifiable Map view of this list.
override
-
asNameMap(
) → Map< String, T> -
Available on Iterable<
Creates a map from the names of enum values to the values.T> , provided by the EnumByName extension -
asRchunks(
int chunkSize) → (Arr< T> , Arr<Arr< )T> > -
Splits the slice into a slice of N-element arrays, starting at the end of the slice,
and a remainder slice with length strictly less than N.
Panics if
chunkSize
is 0 or less. -
asSlice(
) → Slice< T> -
Available on List<
T> , provided by the Slice$ListExtension extension -
asSlice(
) → Slice< T> -
binarySearch(
T x) → Result< int, int> -
Available on Slice<
Binary searches this slice for a given element. If the slice is not sorted, the returned result is unspecified and meaningless.T> , provided by the Slice$SliceComparableSelfExtension extension -
binarySearchBy(
int comparator(T)) → Result< int, int> -
Binary searches this slice with a comparator function. See
SliceOnComparableSliceExtension.binarySearch
for more. -
binarySearchByKey<
K extends Comparable> (K key, K keyExtractor(T)) → Result< int, int> -
Binary searches this slice with a key extraction function. See
SliceOnComparableSliceExtension.binarySearch
for more. -
byName(
String name) → T -
Available on Iterable<
Finds the enum value in this list with nameT> , provided by the EnumByName extensionname
. -
call(
RangeBounds range) → Slice< T> -
Available on List<
T> , provided by the OpsListExtension extension -
call(
RangeBounds range) → Iterable< T> -
cast<
U> () → Slice< U> -
Returns a slice view where the elements are
U
.override -
chunkBy(
bool compare(T, T)) → Iter< Slice< T> > -
Returns an iterator over the slice producing non-overlapping runs of elements
using the predicate to separate them.
[1, 1, 1, 3, 3]
=>[[1, 1, 1], [3, 3]]
for(a, b) => a == b
The predicate is called for every pair of consecutive elements. -
chunks(
int n) → Iter< Slice< T> > -
Returns an iterator over
chunkSize
elements of the slice at a time, starting at the beginning of the slice. The chunks are slices and do not overlap. IfchunkSize
does not divide the length of the slice, then the last chunk will not have length chunkSize. Panics ifchunkSize
is 0 or less. -
clear(
) → void -
Clears the underlying data the slice encompasses. This slice's length after will be zero.
Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.
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 this.
-
copyWithin(
int start, int end, int dst, {bool sInc = true, bool enInc = false}) → void -
Copies elements from one part of the slice to another part of itself
The edge conditions can be changes with
sInc
andeInc
.sInc
is whether the start is inclusive andeInc
is whether the end is inclusive. -
dedup(
) → void -
Available on List<
Removes consecutive repeated elements in the vector according toT> , provided by the Vec$ListExtension extension==
. If the vector is sorted, this removes all duplicates. -
dedupBy(
bool f(T a, T b)) → void -
Available on List<
Removes all but the first of consecutive elements in the vector satisfying a given equality relation. If the vector is sorted, this removes all duplicates.T> , provided by the Vec$ListExtension extension -
dedupByKey<
K> (K f(T)) → void -
Available on List<
Removes all but the first of consecutive elements in the vector for which the given predicate returns true. If the vector is sorted, this removes all duplicates.T> , provided by the Vec$ListExtension extension -
drain(
int start, int end) → Vec< T> -
Available on List<
Removes the element at the given index from the Vec and returns it.T> , provided by the Vec$ListExtension extension -
elementAt(
int index) → T -
Returns the
index
th element.override -
elementAtOrNull(
int index) → T? -
Available on Iterable<
The element at positionT> , provided by the IterableExtensions extensionindex
of this iterable, ornull
. -
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)) → Iter<U> -
Expands each element of this Iterable into zero or more elements.
override
-
extendFromSlice(
Slice< T> slice) → void -
Available on List<
Appends all elements in a slice to the Vec.T> , provided by the Vec$ListExtension extension -
extendFromWithin(
int start, int end) → void -
Available on List<
T> , provided by the Vec$ListExtension extension -
extractIf(
bool f(T)) → Iter< T> -
Available on List<
Creates an Iter which uses a closure to determine if an element should be removed. If the closure returns true, then the element is removed and yielded. If the closure returns false, the element will remain in the vector and will not be yielded by the iterator.T> , provided by the Vec$ListExtension extension -
fill(
T value) → void -
Fills this slice with
value
. -
fillRange(
int start, int end, [T? fillValue]) → void -
Overwrites a range of elements with
fillValue
.override -
fillWith(
T f()) → void -
Fills this slice with the value return by calling
f
repeatedly. -
firstOrOption(
) → Option< T> -
Available on List<
Returns the first element of an iterator, None if empty.T> , provided by the Vec$ListExtension extension -
firstWhere(
bool f(T), {T orElse()?}) → T -
The first element that satisfies the given predicate
test
.override -
flatten(
) → Vec< T> -
Available on List<
List< , provided by the Vec$ListListExtension extensionT> > -
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) → Iter<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(
Arr< int> indices) → Result<Arr< T> , GetManyError> - Returns many indices at once. Returns an error if any index is out-of-bounds.
-
getManyUnchecked(
Arr< int> indices) → Arr<T> - Returns mutable references to many indices at once, without doing any checks.
-
getRange(
int start, int end) → Iterable< T> -
Creates an Iterable that iterates over a range of elements.
override
-
getUnchecked(
int index) → T - Returns the element at the given index without doing bounds checking.
-
indexOf(
T element, [int start = 0]) → int -
The first index of
element
in this list.override -
indexWhere(
bool test(T element), [int start = 0]) → int -
The first index in the list that satisfies the provided
test
.override -
insert(
int index, T element) → void -
Inserts
element
at positionindex
in this slice. This increases the length of the underlying list and this slice by one and shifts all objects at or after the index towards the end. The underlying list must be growable. Theindex
value must be non-negative and no greater than length. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
insertAll(
int index, Iterable< T> iterable) → void -
Inserts all objects of
iterable
at positionindex
in this slice. This increases the length of the slice by the length ofiterable
and shifts all later objects towards the end of the slice. The underlying list must be growable. Theindex
value must be non-negative and no greater than length. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
isSorted(
) → bool -
Available on Slice<
Checks if the elements of this slice are sorted. That is, for each element a and its following element b, a <= b must hold.T> , provided by the Slice$SliceComparableSelfExtension extension -
isSorted(
) → bool -
Available on Slice<
Checks if the elements of this slice are sorted. That is, for each element a and its following element b, a <= b must hold.T> , provided by the Slice$SliceNumExtension extension -
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(
) → Iter< T> -
Available on Iterable<
Returns an Iter over the Iterable.T> , provided by the Iter$IterableExtension extension -
iter(
) → Iter< T> -
Available on List<
T> , provided by the Vec$ListExtension extension -
iter(
) → Iter< T> -
join(
[String separator = '']) → String -
Converts each element to a String and concatenates the strings.
override
-
lastChunk(
int n) → Arr< T> ? - Return an array with the last N items in the slice. If the slice is not at least N in length, this will return null.
-
lastChunkOpt(
int n) → Option< Arr< T> > - Return an array with the last N items in the slice. If the slice is not at least N in length, this will return None.
-
lastIndexOf(
T element, [int? start]) → int -
The last index of
element
in this list.override -
lastIndexWhere(
bool test(T element), [int? start]) → int -
The last index in the list that satisfies the provided
test
.override -
lastOrOption(
) → Option< T> -
Available on List<
Returns the last element of an iterator, None if empty.T> , provided by the Vec$ListExtension extension -
lastWhere(
bool f(T), {T orElse()?}) → T -
The last element that satisfies the given predicate
test
.override -
len(
) → int -
Available on List<
insert: Already implemented by list Returns the length of the Vec. Equivalent to length.T> , provided by the Vec$ListExtension extension -
len(
) → int - Returns the length of the slice.
-
map<
U> (U f(T)) → Iter< U> -
The current elements of this iterable modified by
toElement
.override -
merge(
) → Result< List< S> > -
Available on Iterable<
Merges an Iterable of results into a single result where the Ok value is the list of all successes. If any Error is encountered, the first Error becomes the root to the rest of the Errors. Similar to toResult.Result< , provided by the AnyhowIterableResultExtension extensionS> > -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
partitionDedup(
) → (Slice< T> , Slice<T> ) -
Available on Slice<
Moves all consecutive repeated elements to the end of the slice according to Comparable. Returns two slices. The first contains no consecutive repeated elements. The second contains all the duplicates in no specified order. If the slice is sorted, the first returned slice contains no duplicates.T> , provided by the Slice$SliceComparableSelfExtension extension -
partitionDedupBy(
bool sameBucket(T, T)) → (Slice< T> , Slice<T> ) -
Moves all consecutive repeated elements to the end of the slice according to Comparable.
Returns two slices. The first contains no consecutive repeated elements. The second contains all the duplicates in no specified order.
The
sameBucket
function is passed the to two elements from the slice and must determine if the elements compare equal. The elements are passed in opposite order from their order in the slice, so if same_bucket(a, b) returns true, a is moved at the end of the slice. If the slice is sorted, the first returned slice contains no duplicates. -
partitionDedupByKey<
K extends Comparable< (K> >K key(T)) → (Slice< T> , Slice<T> ) - Moves all but the first of consecutive elements to the end of the list that resolve to the same key. Returns two slices. The first contains no consecutive repeated elements. The second contains all the duplicates in no specified order. If the list is sorted, the first returned list contains no duplicates.
-
partitionPoint(
bool predicate(T)) → int -
Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).
The slice is assumed to be partitioned according to the given predicate. This means that all elements for which the predicate returns
true are at the start of the slice and all elements for which the predicate returns false are at the end.
For example,
7, 15, 3, 5, 4, 12, 6
is partitioned under the predicate x % 2 != 0 (all odd numbers are at the start, all even at the end). If this slice is not partitioned, the returned result is unspecified and meaningless, as this method performs a kind of binary search. -
pop(
) → T? -
Available on Vec<
Removes the last element from the Vec and returns it, or None if it is empty.T> , provided by the Vec$VecConcreteExtension extension -
popOpt(
) → Option< T> -
Available on List<
Removes the last element from the Vec and returns it, or None if it is empty.T> , provided by the Vec$ListExtension extension -
push(
T element) → void -
Available on List<
Appends an element to the end of the Vec. Equivalent to add.T> , provided by the Vec$ListExtension extension -
rchunks(
int chunkSize) → Iter< Slice< T> > -
Returns an iterator over
chunkSize
elements of the slice at a time, starting at the end of the slice. The chunks are slices and do not overlap. If chunk_size does not divide the length of the slice, then the last chunk will not have lengthchunkSize
. Panics ifchunkSize
is less than or equal to zero -
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
-
remove(
Object? value) → bool -
Removes the first occurrence of
value
from this slice. Returns true ifvalue
was in the slice, false otherwise. The slice must be growable. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
removeAt(
int index) → T -
Removes the object at position
index
from this slice. This method reduces the length of this slice and the underlying list by one and moves all later objects down by one position. Returns the removed value. Theindex
must be in the range 0 ≤ index < length. The underlying list must be growable. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
removeLast(
) → T -
Removes and returns the last object in this list. The list must be growable and non-empty.
Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.
override
-
removeRange(
int start, int end) → void -
Removes a range of elements from the slice and the underlying list.
Removes the elements with positions greater than or equal to
start
and less thanend
, from the slice and underlying list. This reduces the slice and underlying list's length by end - start. The provided range, given bystart
andend
, must be valid. A range fromstart
toend
is valid if 0 ≤ start ≤ end ≤ length. An empty range (with end == start) is valid. The list must be growable. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
removeWhere(
bool test(T element)) → void -
Removes all objects from this slice and the underlying list that satisfy
test
. An object o satisfiestest
if test(o) is true. The slice's range shrinks by the number of elements removed. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
replaceRange(
int start, int end, Iterable< T> replacements) → void -
Replaces a range of elements with the elements of
replacements
. Removes the objects in the range fromstart
toend
, then inserts the elements ofreplacements
atstart
. This will change the size of this slice byreplacements.length - (end - start)
. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
resize(
int newLen, T value) → void -
Available on List<
Resizes the Vec in-place so that len is equal toT> , provided by the Vec$ListExtension extensionnewLen
. IfnewLen
is greater than len, the Vec is extended by the difference, with each additional slot filled with value. If new_len is less than len, the Vec is simply truncated. -
resizeWith(
int newLen, T f()) → void -
Available on List<
Resizes the Vec in-place so that len is equal toT> , provided by the Vec$ListExtension extensionnewLen
. IfnewLen
is greater than len, the Vec is extended by the difference, with each additional slot filled with the result of f. If new_len is less than len, the Vec is simply truncated. -
retain(
bool f(T)) → void -
Available on List<
Retains only the elements specified by the predicate where the result is true. Equivalent to retainWhere.T> , provided by the Vec$ListExtension extension -
retainWhere(
bool test(T element)) → void -
Removes all objects from this list that fail to satisfy
test
. An object o satisfiestest
if test(o) is true. The slice's range shrinks by the number of elements removed. Note, the ranges of other slices on the underlying list will not change, therefore use with care as this may shift the underlying data in other slices.override -
reverse(
) → void - Reverses the order of elements in the slice, in place.
-
rotateLeft(
int mid) → void -
Rotates the slice in-place such that the first mid elements of the slice move to the end while the
last
this.len() - mid
elements move to the front. After calling rotateLeft, the element previously at index mid will become the first element in the slice. -
rotateRight(
int k) → void -
Rotates the slice in-place such that the first
this.len() - k
elements of the slice move to the end while the last k elements move to the front. After calling rotate_right, the element previously at indexthis.len() - k
will become the first element in the slice. -
rsplit(
bool pred(T)) → Iter< Slice< T> > - Returns an iterator over slices separated by elements that match pred, starting at the end of the slice and working backwards. The matched element is not contained in the slices.
-
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).
-
rsplitn(
int n, bool pred(T)) → Iter< Slice< T> > - Returns an iterator over slices separated by elements that match pred, limited to returning at most n items, starting from the end. The matched element is not contained in the slices. The last element returned, if any, will contain the remainder of the slice.
-
rsplitOnce(
bool pred(T)) → (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 null.
-
rsplitOnceOpt(
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.
-
setAll(
int index, Iterable< T> iterable) → void -
Overwrites elements with the objects of
iterable
. The elements ofiterable
are written into this list, starting at positionindex
. This operation does not increase the length of the slice or the underlying list. Theindex
must be non-negative and no greater than length. Theiterable
must not have more elements than what can fit fromindex
to length. If iterable is based on this slice, its values may change during the setAlloverride -
setRange(
int start, int end, Iterable< T> iterable, [int skipCount = 0]) → void -
Writes some elements of
iterable
into a range of this list. Copies the objects ofiterable
, skippingskipCount
objects first, into the range fromstart
, inclusive, toend
, exclusive, of this slice.override -
setUnchecked(
int index, T value) → void - Sets the element at the given index without doing bounds checking.
-
shuffle(
[Random? random]) → void -
Shuffles the elements of this list randomly.
override
-
singleOrOption(
) → Option< T> -
Available on List<
Returns the single element of an iterator, None if this is empty or has more than one element.T> , provided by the Vec$ListExtension extension -
singleWhere(
bool f(T), {T orElse()?}) → T -
The single element that satisfies
test
.override -
skip(
int count) → Iter< T> -
Creates an Iterable that provides all but the first
count
elements.override -
skipWhile(
bool f(T)) → Iter< T> -
Creates an
Iterable
that skips leading elements whiletest
is satisfied.override -
slice(
[int start = 0, int? end]) → Slice< T> -
slice(
[int start = 0, int? end]) → Slice< T> -
Available on List<
T> , provided by the Slice$ListExtension extension -
sort(
[int compare(T a, T b)?]) → void -
Sorts this slice according to the order specified by the
compare
function.override -
sortUnstable(
) → void -
Available on Slice<
Sorts the slice, but might not preserve the order of equal elements.T> , provided by the Slice$SliceNumExtension extension -
sortUnstable(
) → void -
Available on Slice<
Sorts the slice, but might not preserve the order of equal elements.T> , provided by the Slice$SliceComparableSelfExtension extension -
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.
-
splice(
int start, int end, Iterable< T> replaceWith) → Vec<T> -
Available on List<
Creates a splicing iterator that replaces the specified range in the vector with the givenT> , provided by the Vec$ListExtension extensionreplaceWith
iterator and yields the removed items. replace_with does not need to be the same length as range. -
split(
bool pred(T)) → Iter< 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(
) → (T, Slice< T> )? - Returns the first and all the rest of the elements of the slice, or null if it is empty.
-
splitFirstOpt(
) → 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)) → Iter< 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(
) → (T, Slice< T> )? - Returns the last and all the rest of the elements of the slice, or null if it is empty.
-
splitLastOpt(
) → 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)) → Iter< 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.
-
splitOff(
int at) → Vec< T> -
Available on List<
Splits the collection into two at the given index. Returns a newly allocated vector containing the elements in the range [at, len). After the call, the original vector will be left containing the elements [0, at).T> , provided by the Vec$ListExtension extension -
splitOnce(
bool pred(T)) → (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.
-
splitOnceOpt(
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) → Slice<T> ? - Returns a subslice with the prefix removed. Returns null if the prefix is not present.
-
stripPrefixOpt(
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) → Slice<T> ? - Returns a subslice with the suffix removed. Returns null if the suffix is not present.
-
stripSuffixOpt(
Slice< T> suffix) → Option<Slice< T> > - Returns a subslice with the suffix removed. Returns None if the suffix is not present.
-
sublist(
int start, [int? end]) → List< T> -
Returns a new list containing the elements between
start
andend
.override -
swap(
int i, int j) → void - Swaps two elements in the slice. Will throw if the indices are out of bounds.
-
swapRemove(
int index) → T -
Available on List<
Removes an element from the vector and returns it. The removed element is replaced by the last element of the vector.T> , provided by the Vec$ListExtension extension -
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 panic if the length of other is not the same as this.
-
take(
int count) → Iter< T> -
Creates a lazy iterable of the
count
first elements of this iterable.override -
takeEnd(
int from) → Slice< T> ? - Returns a new slice of this slice from the end, and removes those elements from this slice. Returns null and does not modify the slice if the given range is out of bounds.
-
takeEndOpt(
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(
) → T? -
Available on Slice<
T> , provided by the Slice$SliceConcreteExtension extension -
takeFirstOpt(
) → Option< T> -
takeLast(
) → T? -
Available on Slice<
T> , provided by the Slice$SliceConcreteExtension extension -
takeLastOpt(
) → Option< T> -
takeStart(
int to) → 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.
-
takeStartOpt(
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)) → Iter< T> -
Creates a lazy iterable of the leading elements satisfying
test
.override -
toArr(
) → Arr< T> -
Available on Iterable<
Creates an Array from an IterableT> , provided by the Array$IterableExtension extension -
toList(
{bool growable = true}) → List< T> -
growable
is ignore, always returns a growable list.override -
toNullables(
) → Iterable< T?> -
Available on Iterable<
Option< , provided by the Iter$IterableOption extensionT> > -
toOptions(
) → Iterable< Option< T> > -
Available on Iterable<
T?> , provided by the Iter$IterableNullable extension -
toResult(
) → Result< List< S> , List<F> > -
Available on Iterable<
Transforms an Iterable of results into a single result where the ok value is the list of all successes and err value is a list of all failures.Result< , provided by the Result$IterableResultExtension extensionS, F> > -
toResult(
) → FutureResult< List< S> , List<F> > -
Available on Iterable<
Transforms an Iterable ofFutureResult< , provided by the Result$IterableFutureResultExtension extensionS, F> >FutureResult
s into a single result where the ok value is the list of all successes and err value is a list of all failures. The order ofS
andF
is determined by the order in the List. -
toResult(
) → Result< List< S> > -
Available on Iterable<
Transforms an Iterable of results into a single result where the Ok value is the list of all successes. The Err type is an Error with list of all errors List<Error>. Similar to merge.Result< , provided by the AnyhowIterableResultExtension extensionS> > -
toResultEager(
) → Result< List< S> , F> -
Available on Iterable<
Transforms an Iterable of results into a single result where the ok value is the list of all successes. If any error is encountered, the first error is used as the error result.Result< , provided by the Result$IterableResultExtension extensionS, F> > -
toResultEager(
) → FutureResult< List< S> , F> -
Available on Iterable<
Transforms an Iterable ofFutureResult< , provided by the Result$IterableFutureResultExtension extensionS, F> >FutureResult
s into a single result where the ok value is the list of all successes. If any error is encountered, the first error is used as the error result. The order ofS
andF
is determined by the order in which futures complete. -
toSet(
) → Set< T> -
Creates a Set containing the same elements as this iterable.
override
-
toString(
) → String -
A string representation of this object.
override
-
toVec(
) → Vec< T> -
Available on Iterable<
T> , provided by the Vec$IterableExtension extension -
truncate(
int newLen) → void -
Available on List<
Shortens the vector, keeping the first len elements and dropping the rest.T> , provided by the Vec$ListExtension extension -
where(
bool f(T)) → Iter< T> -
Creates a new lazy Iterable with all elements that satisfy the
predicate
test
.override -
whereType<
U> () → Iter< U> -
Creates a new lazy Iterable with all elements that have type
T
.override -
windows(
int size) → Iter< Slice< T> > - Returns an iterator of slices of this slice over all contiguous windows of length size. The windows overlap. If the slice is shorter than size, the iterator returns no values. Panics if size is zero or less.
Operators
-
operator +(
List< T> other) → List<T> -
Returns the concatenation of this list and
other
.override -
operator ==(
Object other) → bool -
The equality operator.
override
-
operator [](
int index) → T -
The object at the given
index
in the list.override -
operator []=(
int index, T value) → void -
Sets the value at the given
index
in the list tovalue
.override