List

Abstract list implementation.

List:__init(values)

View source

Constructor.

Arguments:

  • values (table[any]): used to initialize the list. Optional.

List:add(val, index)

View source

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)

View source

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)

View source

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)

View source

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)

View source

Compares two lists.

Arguments:

  • another (List): another list to compare to.

Returns:

  • (boolean) whether this list is equal to another

Lists are considered equal if their values match at every position.

List:swap(i, j)

View source

Swaps value at two indices.

Arguments:

  • i (int): first index.
  • j (int): second index.

Returns:

  • (List) - modified list

List:totable()

View source

Returns the list in table form.

Returns:

  • (table[any]) a table containing the values in the list.

List:assertValidIndex(index)

View source

Asserts that index is inside the list.

Arguments:

  • index (int): index to check.

List:size()

View source

Returns:

  • (int) size of the list

List:addMany(...)

View source

Adds items to the list.

Arguments:

  • vararg (vararg[any]): values to add to the list.

Returns:

  • (List) modified list

List:contains(val)

View source

Returns whether the list contains a value.

Arguments:

  • val (any): value to check.

Returns:

  • (boolean) whether val is in the list

List:copy()

View source

Returns:

  • (List) a copy of this list

List:isEmpty()

View source

Returns:

  • (boolean) whether the list is empty

List:sublist(start, finish)

View source

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)

View source

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__()

View source

Returns:

  • (string) string representation