List
Abstract list implementation.
List:__init(values)
Constructor.
Arguments:
values(table[any]): used to initialize the list. Optional.
List:add(val, index)
Adds element to list.
Arguments:
val(any): value to add.index(int): index to add value at. Optional, Default:end.
Returns:
- (
List) - modified list
List:get(index)
Arguments:
index(int): index to retrieve value for.
Returns:
- (
any) - value at index
Asserts error if index is out of bounds.
List:set(index, val)
Sets the value at index.
Arguments:
index(int): inde to set value for.val(any): value to set.
Returns:
- (
List) - modified list
Asserts error if index is out of bounds.
List:remove(index)
Arguments:
index(int): index to remove at.
Returns:
- (
any) - value at index
Elements after index will be shifted to the left by 1.
Asserts error if index is out of bounds.
List:equals(another)
Compares two lists.
Arguments:
another(List): another list to compare to.
Returns:
- (
boolean) whether this list is equal toanother
Lists are considered equal if their values match at every position.
List:swap(i, j)
Swaps value at two indices.
Arguments:
i(int): first index.j(int): second index.
Returns:
- (
List) - modified list
List:totable()
Returns the list in table form.
Returns:
- (
table[any]) a table containing the values in the list.
List:assertValidIndex(index)
Asserts that index is inside the list.
Arguments:
index(int): index to check.
List:size()
Returns:
- (
int) size of the list
List:addMany(...)
Adds items to the list.
Arguments:
vararg(vararg[any]): values to add to the list.
Returns:
- (
List) modified list
List:contains(val)
Returns whether the list contains a value.
Arguments:
val(any): value to check.
Returns:
- (
boolean) whethervalis in the list
List:copy()
Returns:
- (
List) a copy of this list
List:isEmpty()
Returns:
- (
boolean) whether the list is empty
List:sublist(start, finish)
Returns a copy of a segment of this list.
Arguments:
start(int): start of the segment.finish(int): start of the segment. Optional, Default:end.
List:sort(start, finish)
Sorts the list in place.
Arguments:
start(int): start index of the sort. Optional, Default:1.finish(int): end index of the sort. Optional, Default:end.
List:__tostring__()
Returns:
- (
string) string representation