PsList class final
Represents a heterogeneous sequence of values in the PackStream format.
Lists permit a mixture of types within the same list and can contain any PackStream data types. The size of a list denotes the number of items within that list, rather than the total packed byte size.
Available representations:
- Tiny List (1 + content bytes): 0-15 items, marker
0x90-0x9F - List 8 (2 + content bytes): 16-255 items, marker
0xD4 - List 16 (3 + content bytes): 256-65,535 items, marker
0xD5 - List 32 (5 + content bytes): 65,536-2,147,483,647 items, marker
0xD6
This class extends ListBase<PsDataType> to provide standard Dart list operations.
Example:
final list = PsList([
PsInt.compact(1),
PsString("hello"),
PsBoolean(true),
]);
// Access elements
print(list[0]); // PsInt(1)
print(list.length); // 3
// Iterate
for (final item in list) {
print(item.dartValue);
}
- Inheritance
-
- Object
- PsDataType<
List< PsDataType> , List<Object?> > - PsList
- Mixed-in types
Constructors
-
PsList(List<
PsDataType> _values) - Creates a new PackStream list.
- PsList.fromPackStreamBytes(ByteData bytes)
-
Creates a PsList from PackStream bytes.
factory
Properties
-
dartValue
→ List<
Object?> -
Returns the list of Dart values by converting each PackStream value.
no setteroverride
- first ↔ PsDataType
-
The first element.
getter/setter pairinherited
- hashCode → int
-
Returns the hash code for this list.
no setteroverride
- isEmpty → bool
-
Whether this collection has no elements.
no setterinherited
- isNotEmpty → bool
-
Whether this collection has at least one element.
no setterinherited
-
iterator
→ Iterator<
PsDataType> -
Provides an iterator over the list items.
no setteroverride
- last ↔ PsDataType
-
The last element.
getter/setter pairinherited
- length ↔ int
-
Returns the number of items in this list.
getter/setter pairoverride
- marker → int
-
Returns the appropriate marker byte based on the list size.
no setteroverride
-
reversed
→ Iterable<
PsDataType> -
An Iterable of the objects in this list in reverse order.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- single → PsDataType
-
Checks that this iterable has only one element, and returns that element.
no setterinherited
-
value
→ List<
PsDataType> -
Returns the list of PackStream values.
no setteroverride
Methods
-
add(
PsDataType element) → void -
Adds
valueto the end of this list, extending the length by one.inherited -
addAll(
Iterable< PsDataType> iterable) → void -
Appends all objects of
iterableto the end of this list.inherited -
any(
bool test(PsDataType element)) → bool -
Checks whether any element of this iterable satisfies
test.inherited -
asMap(
) → Map< int, PsDataType> -
An unmodifiable Map view of this list.
inherited
-
cast<
R> () → List< R> -
Returns a view of this list as a list of
Rinstances.inherited -
clear(
) → void -
Removes all objects from this list; the length of the list becomes zero.
inherited
-
contains(
Object? element) → bool -
Whether the collection contains an element equal to
element.inherited -
elementAt(
int index) → PsDataType -
Returns the
indexth element.inherited -
every(
bool test(PsDataType element)) → bool -
Checks whether every element of this iterable satisfies
test.inherited -
expand<
T> (Iterable< T> f(PsDataType element)) → Iterable<T> -
Expands each element of this Iterable into zero or more elements.
inherited
-
fillRange(
int start, int end, [PsDataType? fill]) → void -
Overwrites a range of elements with
fillValue.inherited -
firstWhere(
bool test(PsDataType element), {PsDataType orElse()?}) → PsDataType -
The first element that satisfies the given predicate
test.inherited -
fold<
T> (T initialValue, T combine(T previousValue, PsDataType element)) → T -
Reduces a collection to a single value by iteratively combining each
element of the collection with an existing value
inherited
-
followedBy(
Iterable< PsDataType> other) → Iterable<PsDataType> -
Creates the lazy concatenation of this iterable and
other.inherited -
forEach(
void action(PsDataType element)) → void -
Invokes
actionon each element of this iterable in iteration order.inherited -
getRange(
int start, int end) → Iterable< PsDataType> -
Creates an Iterable that iterates over a range of elements.
inherited
-
indexOf(
Object? element, [int start = 0]) → int -
The first index of
elementin this list.inherited -
indexWhere(
bool test(PsDataType element), [int start = 0]) → int -
The first index in the list that satisfies the provided
test.inherited -
insert(
int index, PsDataType element) → void -
Inserts
elementat positionindexin this list.inherited -
insertAll(
int index, Iterable< PsDataType> iterable) → void -
Inserts all objects of
iterableat positionindexin this list.inherited -
join(
[String separator = ""]) → String -
Converts each element to a String and concatenates the strings.
inherited
-
lastIndexOf(
Object? element, [int? start]) → int -
The last index of
elementin this list.inherited -
lastIndexWhere(
bool test(PsDataType element), [int? start]) → int -
The last index in the list that satisfies the provided
test.inherited -
lastWhere(
bool test(PsDataType element), {PsDataType orElse()?}) → PsDataType -
The last element that satisfies the given predicate
test.inherited -
map<
T> (T f(PsDataType element)) → Iterable< T> -
The current elements of this iterable modified by
toElement.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reduce(
PsDataType combine(PsDataType previousValue, PsDataType element)) → PsDataType -
Reduces a collection to a single value by iteratively combining elements
of the collection using the provided function.
inherited
-
remove(
Object? element) → bool -
Removes the first occurrence of
valuefrom this list.inherited -
removeAt(
int index) → PsDataType -
Removes the object at position
indexfrom this list.inherited -
removeLast(
) → PsDataType -
Removes and returns the last object in this list.
inherited
-
removeRange(
int start, int end) → void -
Removes a range of elements from the list.
inherited
-
removeWhere(
bool test(PsDataType element)) → void -
Removes all objects from this list that satisfy
test.inherited -
replaceRange(
int start, int end, Iterable< PsDataType> newContents) → void -
Replaces a range of elements with the elements of
replacements.inherited -
retainWhere(
bool test(PsDataType element)) → void -
Removes all objects from this list that fail to satisfy
test.inherited -
setAll(
int index, Iterable< PsDataType> iterable) → void -
Overwrites elements with the objects of
iterable.inherited -
setRange(
int start, int end, Iterable< PsDataType> iterable, [int skipCount = 0]) → void -
Writes some elements of
iterableinto a range of this list.inherited -
shuffle(
[Random? random]) → void -
Shuffles the elements of this list randomly.
inherited
-
singleWhere(
bool test(PsDataType element), {PsDataType orElse()?}) → PsDataType -
The single element that satisfies
test.inherited -
skip(
int count) → Iterable< PsDataType> -
Creates an Iterable that provides all but the first
countelements.inherited -
skipWhile(
bool test(PsDataType element)) → Iterable< PsDataType> -
Creates an
Iterablethat skips leading elements whiletestis satisfied.inherited -
sort(
[int compare(PsDataType a, PsDataType b)?]) → void -
Sorts this list according to the order specified by the
comparefunction.inherited -
sublist(
int start, [int? end]) → List< PsDataType> -
Returns a new list containing the elements between
startandend.inherited -
take(
int count) → Iterable< PsDataType> -
Creates a lazy iterable of the
countfirst elements of this iterable.inherited -
takeWhile(
bool test(PsDataType element)) → Iterable< PsDataType> -
Creates a lazy iterable of the leading elements satisfying
test.inherited -
toByteData(
) → ByteData -
Converts this list to its PackStream byte representation.
override
-
toBytes(
) → Uint8List -
Converts this PackStream data type to a byte array.
inherited
-
toList(
{bool growable = true}) → List< PsDataType> -
Creates a List containing the elements of this Iterable.
inherited
-
toSet(
) → Set< PsDataType> -
Creates a Set containing the same elements as this iterable.
inherited
-
toString(
) → String -
Returns a string representation of this list.
override
-
where(
bool test(PsDataType element)) → Iterable< PsDataType> -
Creates a new lazy Iterable with all elements that satisfy the
predicate
test.inherited -
whereType<
T> () → Iterable< T> -
Creates a new lazy Iterable with all elements that have type
T.inherited
Operators
-
operator +(
List< PsDataType> other) → List<PsDataType> -
Returns the concatenation of this list and
other.inherited -
operator ==(
Object other) → bool -
Checks if this list equals another object.
override
-
operator [](
int index) → PsDataType -
Gets the item at the specified index.
override
-
operator []=(
int index, PsDataType value) → void -
Sets the item at the specified index.
override